Shuffling through number on repeat starting at 1 (one).
Hello,
I think I asked this before but couldn't remember the answer.
I have 8 numbers; 1,2,3,4,5,6,7,8
When I add +1 to any number I want it to add it. But when it equals 9, goes back to 1.
I had an equation,
(Game.Number+1)%8
But it gives me a 0 (zero) instead of 8 (eight). Is there a way I can fix this in the equation?
Thanks,
Two.E
Comments
(Game.Number %8)+1
Set the attribute's default starting value to 1
What if I am adding a value to the Game.Number.
Game.Number = 8
-- Change Game.Number to Game.Number +1
Now, if I used %8 at the end, it will return 0. If I have (%8)+1, it will increase by 2's.
The best solution I have found so far is the following,
---- Change "Game.Number" to "Ceil((Game.Number +1)%8.99)
Attached is a file (Touch Actor to change number +1)
Thanks,
Two.E
GSLearn.com | Templates | Free Demos | Udemy Course
I think there is a psychological attraction to overly complex solutions to simple problems amongst us GameSalad users
Did you try my suggestion above ? It works !
"What if I am adding a value to the Game.Number"
@Socks, Thanks.
Thanks. Also happy to learn something new.
However if you look at the demo attached.
Two Attributes.
Game.Start
Game.END
When the actor is pressed, it will:
Change "Game.Start" to "(Game.Start%8)+1"
(This will give me a number from 1-8 which is perfect)
Then I need Game.End to be equal to Game.Start minus 4 (or any value) but still only display the answer between 1-8.
If I use:
(Game.Start-4)%8
I get an answer from 0-7.
If I use:
((Game.Start - 4)%8)+1
I get either, 2,4,6,8
Thanks again for your suggestions.
Two.E
GSLearn.com | Templates | Free Demos | Udemy Course
If you start with a value from 1 to 8 and then subtract 4, the result is not going to be between 1 and 8. It's going to be between -3 and 4. What range of values do you want the final result to be in? You said between 1 and 8 but do you mean between 1 and 4? Is there a reason you can't just subtract 4 from Game.Start after you calculate its value?
Sorry, I haven't looked at the demo file... haven't had time.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
(start-5)%8+1
"or any value . . . "
(start-A)%8+1
A=value+1
@ Socks.
I made a demo that does what you are saying.
It still double counts.
Not sure where my mistake is.
GSLearn.com | Templates | Free Demos | Udemy Course
Not sure what 'double counts' means ?
Your demo file works fine for me, it fits this description: (start-A)%8+1 . . . . where A = the value+1.
So, your equation is (self.start-4)%8+1 . . . so A is 4, which is the value +1, therefore the value is 3, and so your demo project displays 'start' / 'start'-3.
What would help us help you is to know the pattern of values you expect. For example:
"Start ƒ" represents the function you first asked about which is Change "Game.Start" to "(Game.Start%8)+1"
I just guessed at those values but you know the actual expected outcomes so once we have that list we can give you the math that fits it.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
As far as I can tell what's required is a fixed offset between the start and end values (I think!?) with both the start and end values 'looping' around the 1-8 range.
So (I think) this is what he's after (using -4 as the offset)
(start/end)
1/5
2/6
3/7
4/8
5/1
6/2
7/3
8/4
Which is what I suggested with (start-A)%8+1, so for example . . .
If the end value needs to be 4 less than the start value you would use: (start-5)%8+1
If the end value needs to be 3 less than the start value you would use: (start-4)%8+1
If the end value needs to be 2 less than the start value you would use: (start-3)%8+1
etc etc . . .
But I'm not so sure that's what he needs now given his feedback ?
@socks
That is correct. Those are the values I am looking for.
Look at the demo. I am sure I did exactly what you suggested and I am getting something like.
Start / End
8 / 4
1 / 6
2 / 8
3 / 2
4 / 4
5 / 6
6 / 8
Notice that the end is changing in twos.
That is the problem. I am not getting the right results,
Thanks,
GSLearn.com | Templates | Free Demos | Udemy Course
I tried your demo, and like I say it works fine for me !? Are you sure we are both looking at the same demo ? I download 'Demo 3.gameproj', where the rule for the end value is:
(self.start -4)%8+1.
You are telling the actor to make the end value 3 less than the start value - and that's just what it does (for the version I have at least) ?
This is what your demo gives me . . . .
1 / 6
2 / 7
3 / 8
4 / 1
5 / 2
6 / 3
7 / 4
8 / 5
@Socks
Thanks for all your help. I solved the problem.
I re-installed GS. Everything works fine now (Strange).
I get exactly what you are reporting which is great!
Apologizes for not solving it earlier.
GSLearn.com | Templates | Free Demos | Udemy Course
Good !