Always run once (sounds odd but stick with me:-))

zerosimms

  • Posts: 710
A really, really helpful block to have would be some form of block that re-runs any attached code a defined amount.

This block would be able to fit inside the 'Always'.

The problem I have is say I want to increase the coin count by one when a player wins, it continues to increase the coin amount because it's in the always block, but I need it to be in the 'always' block because it has to be continuously listening out for the win call.

applaud

  • Posts: 370
Erm sorry if I misunderstood but just don't do that in the "always" block.

How do you send out the win call? Can't you just use a custom event (which is always listening for a single message) attached to the scene or some actor :

when hears "win" increment coin count

It hears the win call once and increments only once.

zerosimms

  • Posts: 710
I've tried a custom event but that appears to behave the same as 'always'. I've attached a screenshot of my setup... Obviously doing something wrong, I know I've done it before but cant think how. Still think having a block would be much easier and quicker

saulochina

  • Posts: 214
you can set always to run once when the condition is trigger, just uncheck the box on the right of the always inside the behavior.
Finding the fun!
Squib Wars. Now complete, and avaible for free on App Store! http://bit.ly/LxJ62L
https://www.facebook.com/twoheadedgames
Twitter: @saulochina
MSN: sauloj.china@hotmail.com

applaud

  • Posts: 370
I think the problem is that when drawing happens every frame like an always. I don't use drawing because I make games for iOS but I'm pretty sure your 'add' message is being broadcast 60 times a second (or whatever framerate you have) whenever drum1result=1.

Ideally you should fix it so that the 'add' event only happens once but I don't know that 'drum 1 result' means or how its set. Can you set it to zero at the same time so that 'add' event happens just once?

Also if the 'credit added' flag was an attempt to get it to happen just once you shouldn't need that attribute. If you broadcast the 'add' event just once. when it hears it it will add credit just once.

Hope this helps a little in getting to the bottom of it but 99% sure the problem is in your when drawing block.

zerosimms

  • Posts: 710
you can set always to run once when the condition is trigger, just uncheck the box on the right of the always inside the behavior.

Hey,

I think I know what you are talking about, though the options seem to have vanished... :( (screenshot attached)

captaincomic

  • *
  • Posts: 6108
Usually I would write this if I want something to happen once:

<always>
  <if <<Condition Met> and <not <Done>>>>
    * do stuff (e.g. trigger an event) *
    <set Done to <true>>

In your setup the problem seems to be that you always set "Credit Added" to true before you trigger the event.

I think I know what you are talking about, though the options seem to have vanished... :(
The option to turn off "repeat" for events is not available for mobile games (but I think it will be in 3.0. ;))

zerosimms

  • Posts: 710
Cheers Comic!

I'll give that a go, I actually managed to get it working this morning but it's a hack and looks untidy :)

h1rnz1lla

  • *
  • Posts: 649
why not use a event? trigger it and it will run once.

zerosimms

  • Posts: 710
Because on mobile the option to run once on an event is missing... At the moment at least :(

applaud

  • Posts: 370
why not use a event? trigger it and it will run once.

That was my suggestion too. You don't need an option to run it once - its how you trigger it that count.

froz

  • Posts: 250
His problem is that the event would be triggered every frame anyway. I would do it the way captaincomic descriped it.