spawning with a timer.

Trouble using a timer to spawn an actor, could it be that my code is wrong?


Below are my codes.
Take note that initialVelocity is 80 int
Do take note that after implementing timer for spawning every 1 sec, boxes are no longer spawned.




Comments

  • mhedgesmhedges Raised on VCS Member Posts: 634
    edited May 2015

    Where is your actor spawn handler (where you inserted your timer)? Did it move away or get destroyed?

  • tiger27tiger27 Member Posts: 127
    edited May 2015

    @benjaminmage This seems like you have over complicated your code. First, you need to create an attribute called SpawnLocation (You can name it whatever you want) as well as 3 actors.

    For the first actor, make him immovable since he will be the wall.

    For the second actor, all you need to do is make them move up. These will be your blocks.

    For the third, the spawner, type in this code:

    Every 1 second
    Change attribute SpawnLocation to random(1, 2)
    
    If attribute = 1
    Spawn Actor 2
    in the position 184, y relative to _scene_
    
    If attribute = 2 
    Spawn Actor 2
    in the position 538, y relative to _scene_
    
  • benjaminmagebenjaminmage Member Posts: 74

    @mhedges I placed it as a wall at the side. It didn't move or get destroyed.

  • benjaminmagebenjaminmage Member Posts: 74

    @tiger27 Er it's actually another section of codes where it helps me to reduce the amount of time to spawn an actor gradually as well as increase velocity.

  • SocksSocks London, UK.Member Posts: 12,822

    You don't really need to generate a random value for left / right (1 or 2) then check the result of this process to decide which rule is the to run, you can generate this all in one go.

    For example:

    You could simply make the X position of the spawner . . .

    (random (0,1) * 469) + 148

    The will randomly give you either 148 or 617.

  • benjaminmagebenjaminmage Member Posts: 74

    @Socks Tried your method but i'm still achieving this.


  • SocksSocks London, UK.Member Posts: 12,822

    Like this:

  • benjaminmagebenjaminmage Member Posts: 74

    @Socks First things first, did i apply your code correctly? If yes, this is the result i got.


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

    How are you moving the spawned actors and/or scene? @Socks' method works fine for spawning at either side of the scene... depending on the scene size. What is the size of your scene? How often are you spawning actors?

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

  • SocksSocks London, UK.Member Posts: 12,822

    @benjaminmage said:
    Socks First things first, did i apply your code correctly?

    No !

    I made an attribute, I called it X, I changed that attribute to (random(0,1)*469)+148
    I then spawned an actor with a horizontal position of X.

    You changed the spawner's horizontal position to (random(0,1)*469)+148
    You then spawned an actor at the same horizontal position as the spawner.

  • benjaminmagebenjaminmage Member Posts: 74
    edited June 2015

    @tatiang The spawned actors (Boxes) are all moving upwards. The size of my scene is an ipad portrait (i heard its best to create an ipad portrait size for an app). I would like to spawn actors with every 1 sec interval.

  • benjaminmagebenjaminmage Member Posts: 74

    @Socks Oh sorry. Here's the corrected version screenshot and results.


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

    You answered "How are you moving the spawned actors and/or scene?" by saying:

    The spawned actors (Boxes) are all moving upwards.

    That's still really vague. What I meant was, what is the EXACT behavior you are using? For example, are you using a Move behavior set to direction 90 relative to scene and speed 250? Or are you using Interpolate? Or Change Velocity? Or something else?

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

  • benjaminmagebenjaminmage Member Posts: 74

    @tatiang Oh i posted it on my first comment. Here,

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

    Sorry! I missed that somehow.

    And what is the value of game.Velocity at the start and does it ever change and by how much and how often? I'm trying to determine why you have actors bunching up, etc.

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

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2015

    @benjaminmage said:
    Socks Oh sorry. Here's the corrected version screenshot and results.

    I'm not sure the relevance of your second image, my code was part of a conversation about how you might simplify your code so that you don't need to produce a random number, then check that number and apply one of two rules based on what number had been produced - instead you could use the maths I suggested to do all that work in the spawn behaviour itself - my original comment had nothing to do with boxes overlapping or not overlapping ?

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2015

    @tatiang said:
    Sorry! I missed that somehow.

    And what is the value of game.Velocity at the start and does it ever change and by how much and how often? I'm trying to determine why you have actors bunching up, etc.

    Yep, these questions are difficult to answer without the right information, when an attribute is shown without an explanation of what it is, what it does, and what values it uses, the attribute may as well read 'secret value I'm not going to reveal' :smiley:

  • SocksSocks London, UK.Member Posts: 12,822

    This simple setup worked for me - two actors - the spawner and the spawned actor - I set this up on a portrait iPad project.

    Spawner:
    Every second.
    Spawn Actor, X=(random(0,1)* 668)+50, Y=0

    Actor:
    No rules / changed linear velocity attribute Y to 100.

  • SocksSocks London, UK.Member Posts: 12,822

    What is the 'direction 270°' for ?

Sign In or Register to comment.