Spawn and Actor when Stwitch is ON
Team, I have a Switch for turn on / off a Laser wall, If the Player touch the Switch, the switch changes the game.integer value attribute (change attribute game.integer To: 1-game.integer )
If the game.integer = 0 Switch the image to OFF and Destroy Laser wall. This works perfect...
But if I touch the switch again,the image changes to ON but the laser wall doesn't spawn.
This is my rule on Switch:
If the Player collide with Switch: Change Attribute to 1-game.integer (To change the game.integer value to 0) -->
If Attribute game.integer=1 -->
Change Image to ON -->
Span Actor Laser Wall -->
Otherwise -->
Change Image to OFF
On the Laser Wall
Attribute game.integer = 0 -->
Destroy this Actor
Any help or suggestions are welcome, I'm a newbie on GameSalad. Thanks
Comments
Hey @heman85,
How you have your rules written out is kind of confusing. Could you possibly take a screen shot and post it up to see exactly how you have it coded.
Thanks!
After this runs game.integer is now 0
1-0 = 1 this is why it doesn't work. Use the mod() function for this i.e. mod(game.integer+1,2) this will switch between 0 and 1 each time it is pressed.
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
I used this:
mod(game.integer+1,2) and Is working fine, I added a Display Message to show the current value for game.integer and I see it changing from 0 to 1 and vice versa.
But the Laser Wall was destroyed when I change it to 0 and never re-spawn again when the switch change the value to 1.
Any suggestions?
For what it's worth, both of these do the same thing:
change attribute game.integer to mod(game.integer+1,2)
change attribute game.integer to 1-game.integer
That is, given a value of 0, they return 1; given a value of 1, they return 0.
@heman85 You'll need to post a screenshot of your rules. It's not possible (or at least very difficult) to guess what is wrong without seeing your actual rules. Just describing them is often not enough.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok Guys
Here is my Laser Wall Rules
tinypic.com/r/34gajab/8
Here is my Switch Rules
tinypic.com/r/20pzp1h/8
BTW game.integer = game.LaserON
There's your issue right these @heman85!
You have the spawn laser in the laser. You destroy the laser then when you try to spawn it again you are not able to because there is no laser in the game to follow your rules and spawn another one.
Put the spawn laser rules in the switch and tell it where to spawn the laser. Another thing you could do is instead of spawning and destroying the lasers just turn their alpha on and off. When it's alpha = 1 do what it's suppose to when it's "spawned"and when it's alpha = 0 stop doing what you want it to do when it's "destroyed". Hope that makes sense!
You are destroying the actor so it's not going to spawn anything after it's destroyed.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Excellent
I used your suggestion, I created a new rule on the Laser Wall:
If game.LaserOn = 0 Visible false
If game.LaserON = Visible True
On the Player, I created a new rule:
If player collide with Laser and game.LaserOn is 1, Player Dies.
Now Is Working as expected, Thank You Guys for your help
Doh! of course I don't know what I was thinking .
Universal Binary Template - Universal Binary Template Instructions Rev 4 (Short) - Custom Score Display Template
what you want is a "round rules" actor with your spawning logic and load logic, etc.... this is where you put this kind of stuff, not in the actors themselves
Nice suggestion jorkos