Need help (something simple)
tiagojdferreira
Member Posts: 12
Hey guys!
I've just started using gamesalad and I've made a rule that when I press a key it changes a game variable (boolean) from false to true if it's true and otherwise if it's false.
My problem is that when I press the key it keeps changing it really fast and I just want it to change once.
Right now when I press the key, since it changes a lot of times and really fast, sometimes I get the variable true and sometimes false, instead of true when I press once, and false when I press it again.
How can I do that?
Thanks in advance,
I've just started using gamesalad and I've made a rule that when I press a key it changes a game variable (boolean) from false to true if it's true and otherwise if it's false.
My problem is that when I press the key it keeps changing it really fast and I just want it to change once.
Right now when I press the key, since it changes a lot of times and really fast, sometimes I get the variable true and sometimes false, instead of true when I press once, and false when I press it again.
How can I do that?
Thanks in advance,
Comments
http://gamesalad.com/forums/topic.php?id=678#post-3721
Cheers,
QS
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
"Rule when touch press" then do a new rule in to that rule saying "Rule when touch released then change variable to X"
i hope it did help
This will make it like an on/off switch: every time you will press it the given value will be 1 or 0
Could you please help me again.
I copy and paste a text make by firemaplegames its a ver good explanation.
modulo operatator, %, is used to find the remainder after division.
so: 10 % 3 = 1
because 3 goes into the number 10 exactly 3 times, with 1 left over.
and 8 % 4 = 0
because 4 goes into the number 8 exactly 2 times, with 0 left over.
and 17 % 6 = 5
because 6 goes into the number 17 exactly 2 times, with 5 left over.
Well, that's all well and good you say, but how could I possibly benefit from that?!?
That seems like the most useless math function. I could not ever possibly imagine using it!
Ah! But the mod function is very powerful, and used all the time in computer programming:
Here are a few quick examples:
It is used to quickly tell if a number is even or odd. Like this:
(ANYNUMBER) % 2
This will return 0 for an even number, 1 for an odd number.
In GameSalad, it would look like this:
Change Attribute: game.evenOrOdd To: myNumberToTest % 2
When game.evenOrOdd = 0
Display Text: "This number is Even!"
Otherwise
Display Text: "This number is Odd!"
Using that same exact logic, programmers use it to create "zebra stripes" in html tables. I'm sure you've seen a table of data that has alternating white and light gray lines. Your iTunes music library, for example. (although it's very subtle) uses this.
That effect is created like this:
If myCurrentRow % 2 = 0
Use the light gray background
Otherwise
Use the white background
The same logic again for a "toggle" switch:
Make an integer attribute. game.Switch
When you press the mouse button, or touch(pressed) the actor:
Change Attribute: game.Switch = (game.Switch + 1)%2
So the value of Switch is either 0 or 1. You can check for those values.
Another very handy use of the modulo is to use if for setting a limit on something.
This is used a lot in games as well.
Let's say your character collects coins in the game. Like in Super Mario Bros.. Mario can collect 99 coins, then the counter resets to 0, and it keeps going like this forever.
Well the "coin limit" is 99.
And you can use the modulo like this:
So every time Mario gets a coin, do this:
game.totalCoins = game.totalCoins+1%99
Every time the coin counter hits the limit, in this case 99, the counter resets to 0
But it doesn't just have to be a number, it can be an actor's width, or its alpha. anything, really:
self.maxWidth = 250
self.size.width = self.size.width+10%self.maxWidth
Or how about this:
In Asteroids, I want to give the player a bonus ship every 20,000 points
You would do that like this:
If currentScore%20000 = 0
Award a bonus ship
This will happen at 20000,40000,60000 etc...
Or if you're mean:
I want Space Invaders to get harder for every 2 minutes that the Player is at the machine:
if currentTimePlayedinSeconds%120
AlienFireRate=AlienFireRate+1
Or for laying out a grid, or chessboard, in a puzzle game
(you would use this in a loop)
gridSquareX = (currentGridSquareNum%numColumns)*gridSquareWidth
currentGridSquareNum = currentGridSquareNum+1
That should give you some basic ideas!