Is there a way to spawn something with random width?

I am trying to spawn a block that will have a random width between 20-45. I have attempted to do this both through the spawner and the block itself by using a timer and change attribute (it will be on screen for about 5 seconds and it spawns a second one before the first one has disappeared). I would like every time that the block spawns for the width to be randomized but I can't seem to figure out how to do it. (Think flappy bird but with obstacles that change in width).

Comments

  • BBEnkBBEnk Member Posts: 1,764

    use the change attribute behavior in the actor thats being spawned like so change attribute self.size width to Random(20,45) and it will do this once spawned.

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    As the first behavior of your spawned actor, use:

    Change Attribute: self.Size.Width to random(20,45)

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

    New users of GameSalad often struggle with how to get something to change without using a Rule to do so. When an actor first loads on a scene, it starts running through its rule list from top to bottom. If the first item in the rule list is a rule, it will begin to evaluate it. If the first item in the rule list is a behavior, it will immediately execute it.

    So the advice above is correct as far as adding a Change Attribute behavior. Just make sure it's not inside of a rule. The change will occur instantly so you shouldn't even notice it happening; it will just look like it was always that (new) width.

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

  • DasavurDasavur Member Posts: 2
    edited October 2014

    @tatiang said:
    New users of GameSalad often struggle with how to get something to change without using a Rule to do so. When an actor first loads on a scene, it starts running through its rule list from top to bottom. If the first item in the rule list is a rule, it will begin to evaluate it. If the first item in the rule list is a behavior, it will immediately execute it.

    So the advice above is correct as far as adding a Change Attribute behavior. Just make sure it's not inside of a rule. The change will occur instantly so you shouldn't even notice it happening; it will just look like it was always that (new) width.

    So I followed these instructions and put the "Change Attribute: self.size.width to random(20,45)" as the very first thing of the actor that I am wanting to spawn but now it doesn't spawn at all. When I remove the change attribute it starts spawning again though. What am I doing wrong that is making it not spawn the actor if it has the random width connected to it?

    I connected a picture of the rules for the actor I want to spawn.

    Well here it is. imgur.com/s1MME0q

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772

    Did you type in "random(20,45)" by hand or use the expression editor to create it?

    You should use the expression editor.

  • DasavurDasavur Member Posts: 2

    @jamie_c said:
    Did you type in "random(20,45)" by hand or use the expression editor to create it?

    You should use the expression editor.

    That was why, I was typing it by hand. Thank you very much. I've literally been trying to figure this out for a couple of hours. I will make sure to always use the expression editor from now on!

Sign In or Register to comment.