GameSalad

Howdy, Stranger!

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

Spawning Random(1, 5) (actually random) From Another Actor

Homebrew_KidHomebrew_Kid Posts: 21Member
edited March 2014 in Working with GS (PC)

I am able to spawn an actor from another actor with this (updated image):

but it seems to only be taking 1 spawn time (whether it be 2, 4, etc.) and using it consistently. I would like to have the actor spawn after 3 seconds, then maybe after 5 seconds, 3.5 seconds, or 4.

Thanks in advance.

Comments

  • SmokeyAce73SmokeyAce73 EarthPosts: 370Member

    Try ticking run to completion, add the actor to spawn, also why have you selected random(min,max) for the direction? just wondering why no values are in there

    Let me know if you sort it

    Developer For BLUNTentertainment - Feel Free To Message Me! - Free Beginner Templates!

  • tatiangtatiang Posts: 11,845Member, Sous Chef, PRO, Senior Sous-Chef
    edited March 2014

    Unfortunately, the Timer behavior will not re-calculate an expression used for the duration of the timer. As you're noticing, if you have a random() expression, it will calculate the value once and then use that same value every time the Timer runs.

    You'll need to use a custom timer for this. One way to do this is (the Spawn Actor behavior would replace the Log Debugging Behavior below):

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

  • Homebrew_KidHomebrew_Kid Posts: 21Member

    Thank you for the feedback, working on some particles right now.

  • Homebrew_KidHomebrew_Kid Posts: 21Member
    edited March 2014

    @tatiang said:
    You'll need to use a custom timer for this. One way to do this is (the Spawn Actor behavior would replace the Log Debugging Behavior below):

    I'm still trying to grasp this. My guess is to make an internal clock that must be reset to start running the code again.

    Fixed (Spawner actor had invalid attributes): Getting a black screen with the same code but i'll fiddle with it. I have multiple spawner actors coming from a spawner so this could be causing it to black screen.

  • StormyStudioStormyStudio United KingdomPosts: 3,987Member

    You've got access to game time . you can use that as the basis for your custom timer

  • Homebrew_KidHomebrew_Kid Posts: 21Member
    edited March 2014

    Using that same script only spawns 1 enemy for me.

    Lets say:

    set game.time = self.timeStamp

    have the random number be set to 4.

    if game.time >= self.timeStamp + 4
    spawn actor

    How do you reset the attribute to spawn again?

    when time is now 24,
    24 >= 24+4

    The spawn has already happened.

    Here is what I have:

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

    Don't use a custom attribute named game.time. Use the built-in game.Time, which counts up continually while an app is running.

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

  • Homebrew_KidHomebrew_Kid Posts: 21Member

    @tatiang said:
    Don't use a custom attribute named game.time. Use the built-in game.Time, which counts up continually while an app is running.

    I'm using the built in game.time

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

    The idea is that if game.Time is 24, that means that game.timeStamp may have been 22 (for example) and game.duration was 2. Then, the rule will spawn an actor, change game.timeStamp to 24 and self.duration to random(1,5). game.Time will be 24 but because game.Time continually counts up, as soon as it reaches 24+self.duration, it will trigger that rule again and repeat the process I just described.

    I don't use Windows Creator so I didn't realize that game.Time is displayed as game.time but I now see that it is. Sorry for any confusion earlier. In Mac Creator, people sometimes make the mistake of creating a custom attribute called game.time and then confusing it with the built-in attribute.

    Try setting it up exactly as I have it in the screenshot above with no other rule conditions or spawn behaviors... just the log debugging statement. Can you get that to work?

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

  • Homebrew_KidHomebrew_Kid Posts: 21Member
    edited March 2014

    @tatiang said:
    Try setting it up exactly as I have it in the screenshot above with no other rule conditions or spawn behaviors... just the log debugging statement. Can you get that to work?

    After using the exact code there is no black screen. I have displayed the self.duration as a text above the actor (after the rule block) in the stage and tried the same with the self.timeStamp to try and see what is going on.

    The self.timeStamp displays "0" constantly.

    The self.duration displays "2" constantly.

    self.timeStamp should display "1", "2", "3" etc? It seems to be recording the first number, "0.174" or whatever, but does not update to keep up with the game.time. (Display Text: game.time does update.)

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

    Hmm... I'm not sure why that would be happening. Any chance you can send me a link to download your project file (first .zip it and upload it to Dropbox or another file-sharing service)? I can take a look and let you know if there's another reason it's not working.

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

  • Homebrew_KidHomebrew_Kid Posts: 21Member

    @tatiang said:

    Hmm... I'm not sure why that would be happening. Any chance you can send me a link to download your project file (first .zip it and upload it to Dropbox or another file-sharing service)?

    Yep, I'll send you the .zip and .gsproj

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

    Sent you a PM. :)

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

Sign In or Register to comment.