GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Spawning actor from table store

NspeelNspeel Posts: 17Member
edited February 25 in Help Wanted

So I have a store in my app and what I'm trying to do is when I hit "Buy" I want to spawn a tower on the scene... that part is easy.. my issue is I want to make it so when the actor "tower" spawns it can moved around and placed into its permanent spot choosen by the player.

Right now I have a button "store" in which the code entails (pause game, change scene)

--
Inside the "store" you have multiple towers u can buy if your money allows it

--
So when you go to buy a tower my code entails (change attribute money -5, unpause game, spawn actor)

***So my issue right now is I cant seems to spawn an actor onto scene 1 while in scene 2...

***My main problem is going to be when you buy this "tower" I need it to pretty much hover worh your touch on the screen till you click it where you want it permentatly placed...

Comments

  • tatiangtatiang Posts: 11,868Member, Sous Chef, PRO, Senior Sous-Chef

    @Nspeel said:

    ***So my issue right now is I cant seems to spawn an actor onto scene 1 while in scene 2...

    To communicate between actors on different scenes, have one actor change the value of a global attribute (e.g. game.SpawnTower) and have the other actor check for a change in value.

    ***My main problem is going to be when you buy this "tower" I need it to pretty much hover worh your touch on the screen till you click it where you want it permentatly placed...

    You're going to have a hard time getting it to work if you want to click/tap an actor on a paused scene and transfer the mouse down condition to another actor on an unpaused scene. Instead, use my method above and then have an actor signify that it's ready to be clicked. Once the player clicks on that actor, then allow them to drag it into position.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • NspeelNspeel Posts: 17Member

    Thank you I will give this a try..

    Is this why in my store scene when u hit my buy button (unpause game, spawn actor) it will not spawn my actor in the "game scene". It doesnt appear to even spawn an actor anywhere as a matter of fact.

    But i'm going to try the method you gave me and see if I can get this work (after I get off tonight).. I'll comment back after and let u know

  • NspeelNspeel Posts: 17Member

    And just to verify here.. if I can type this in way that is understandable...

    I'm going to add a function to my buy button (store scene) to change global attribute +1
    Then I'm going to have another actor (game scene) look for change in value (if value changed spawn actor)

    If I can get that to work I'm sure I can figure out how to allow them to drag it and drop into its final resting spot.

    Another thing I cant seem to figure out is..
    I want my tower to fire at the enemy that's within firing distance.. what I have done is when actor A collides with Actor B (spawn actor - arrow) then when Actor Arrow Collides with Actor A again (change hit points -1) when actor A hit points are equal to or less than 0 destroy actor A.

    My problem is I'm telling Actor A it has to collide with Actor B.. is there a way to expand actor Bs collidable area... without making it bigger forsay.. so actor A (the tower) has a bigger area to collide with

  • tatiangtatiang Posts: 11,868Member, Sous Chef, PRO, Senior Sous-Chef

    @Nspeel said:
    I'm going to add a function to my buy button (store scene) to change global attribute +1
    Then I'm going to have another actor (game scene) look for change in value (if value changed spawn actor)

    Right. The easiest way to do this is to use the attribute as a "switch" or "toggle." So have it start with the value 0 and then change it to 1. Have an actor that detects if it equals 1 and then spawn whatever you need to spawn, etc. and then change the value back to 0 from that actor so that it resets it.

    Another thing I cant seem to figure out is..
    I want my tower to fire at the enemy that's within firing distance.. what I have done is when actor A collides with Actor B (spawn actor - arrow) then when Actor Arrow Collides with Actor A again (change hit points -1) when actor A hit points are equal to or less than 0 destroy actor A.

    My problem is I'm telling Actor A it has to collide with Actor B.. is there a way to expand actor Bs collidable area... without making it bigger forsay.. so actor A (the tower) has a bigger area to collide with

    You can do this with a custom collision shape using the third-party physics editor but it's probably easier to just use a "mask" actor. The idea is that you have an invisible actor (self.color.Alpha=0) that is behind the visible actor. The visible actor would have no rules (or very few, depending on if you need animations, etc.). The mask actor would have all of the collision rules. You can make the mask actor as large as you want since it's invisible. You can also make it a circle if you prefer by importing a circle with a transparent background (.png) and changing the collision type to "circle" (or "circular", I forget) within the mask actor's attributes.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • NspeelNspeel Posts: 17Member

    Alright so your store idea for changing the attribute was genius.. that worked perfect it did exactly what I wanted.. I was easily able to figure out how to move the new actor "tower" using the contrain feature so it's now able to be dragged and dropped as well... now your idea on the invisible actor having the collision attribute this was how I was going to approach it I just wasn't sure if there was a much easier way.. now since my actor "tower" is able to be dragged around and moved constantly is there a way to spawn this invisible actor "towers invisable range" onto of the actor "tower" everytime its dragged around.. or instead maybe spawn one "towers invisible range" that follows actor "tower" around.

    That being said I have a feeling since there could be 10+ actor "towers", if user buys that many, that I might run into a problem with what "towers invisable range" is designed to do...

    Maybe I can give this an attribute to? Everytime "tower" is spawned (attribute +1) so each tower is assigned an attribute different from the last. Then each will also spawn a "towers invisible range" which ultimately does the same thing but will then join each other... does that make sense? Is that possible in anyway

  • JB makin' a gameJB makin' a game Posts: 39Member, BASIC
    edited February 26

    To let your invisible actor stick to the position of your visible tower wherever it goes, you can use constrain attributes. Constrain scene/game attributes to position.x and y of the visible actor and constrain position.x and y of the invisible actor to the same scene/game attributes.
    Since constrain attributes way heavy on your performance, be sure to put them inside a rule, that says something like:
    if tower is dragged,
    constrain position.x and y
    else set position.x and y

    So when the tower is placed on the field somewhere, it stops constraining its position, because it's standing still anyway. Instead it sets its position to where it is at that moment and the invisible actor will do the same, turning off all constrained attributes.

    I don't know if there's a way to do this with less than four constrained attributes, if you want position.x and y both moving around. If it can be done with less, go for that!

    As for the last part of your question: Do you mean that when the invisble actors overlap and an enemy is within the range of two invisible actors, it gets hurt more? Because that's exactly what's gonna happen. A rule within the invisible actor that says:
    if enemy collides with actor
    set attr.HealthBar to HealthBar -1

    Now if the enemy is within the range of two (or more) invisible actors, the invisible actors will all perform that same code, thus setting HealthBar to -1 multiple times. And yeah, you can make every spawned actor change an attribute to change the impact that multiple towers have. It seems you're on the right track, so play around with it.

  • NspeelNspeel Posts: 17Member

    What is this set position feature? I cant seem to find anything remotely close..

    And if possible could u give me a brief example of "Constrain scene/game attributes to position.x and y of the visible actor and constrain position.x and y of the invisible actor to the same scene/game attributes."

    I should of started with a simpler game to be honest but i`m already deep into this one. Like 20 hours deep Haha. Which I'm sure isn't anything remotely close to what some of the people got into there games months/years of development. But I'm getting the hang of gamesalad pretty quickly I cant wait to upgrade my plan

  • NspeelNspeel Posts: 17Member

    Save attribute be the same as set attribute?

  • NspeelNspeel Posts: 17Member

    Solved! Thanks everyone

Sign In or Register to comment.