Help needed with a bit of code...
Hi, I was wondering if anyone fancied having a crack at this because I'm struggling to find a simple method?:
I've got 8 buttons which can be pressed in any order to turn them either ON or OFF.
However, only 3 buttons can ever be turned ON at any one time. If the player were to press a 4th button then the 1st button that had been pressed will turn itself off, if they then pressed a 5th button then the 2nd button that had been pressed will turn itself off etc...
However, the player can also turn off a button himself if he wished - so therefore if the player had turned on buttons 1, 2 and 3 in that order, then turned off button 2, then turned on button 4 we would now have buttons 1, 3 and 4 on (no button would turn itself off automatically). If they now pressed button 5, button 1 would go off. Then if they pressed button 6, button 3 would go off etc etc.
Hope I'm making myself clear! - Would be great if one of the code whizzes around here fancied casting there eyes over this one??
Cheers!
Comments
My internet at the moment is simply abysmal so I don't know if this will upload successfully, but since it's only 50k, fingers crossed.
I'm sure there is a cleaner way to do it, but this seems to work.
One self attribute and one game attribute required, no tables. I used a second self-attribute to number the buttons but it can be safely removed.
This kind of thing highlights how useful it would be if you could demand GameSalad ran behaviours in order.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
@Armelline - that's great, works a treat! I know someone would make it seem so easy!
Thank you!!
@Armelline - I've found a slight flaw in your solution... and again can't get my head around a simple fix.
Here's the issue:
If you turn on button 1, 2 and 3 then turn off the 1st button it breaks the project. You can now turn on all the buttons at the same time.
The problem lies with the code:
WHEN game.ButtonCount < self.ButtonOrder
CHANGE ATTRIBUTE: self.ButtonOrder TO self.ButtonOrder-1
I was curious about how one would do this with a table. So here one way.
Basically when you release a button, it inserts the button's name in the last row of a table. If there are more than 3 rows in the table, it deletes the first row.
Then if the button can find its name in the table, it lights up. Otherwise it unhighlights.
@RThurman - great, works perfectly! Thanks for taking the time to look at this.
Cheers!
@DigiChain said
I've just put two and two together and realised that the games I've recently been playing with my 6 year old son are yours !! I thought they might have been GameSalad games (the loading wheel), but I only realised whose they were today.
He loves point and click adventure games, we've done Lost Temples and are just starting on Magic Castle.
Glad it will work for you!
(It came in handy for me today too.)
@RThurman - Great, everyones a winner then! ;-)
@Socks - Excellent! Always good to hear the kids still enjoy a bit of point & click adventuring these days too!
He absolutely loves them, as soon as we've finished one literally within seconds he's all "can we buy another one, they're only 69p, can we buy another one, can we buy another one . . . "