trigger something only once
#1
Posted 26 June 2011 - 06:12 PM
in a step event how can i trigger something only oance?or not necesarly only step event, in general i need to trigger something only oance.but i need to trigger it again some time later.for example if X>y do this... then stop, the code will eventualy build enaugh units so that x<y but i need the code to run again(only oance again) in the future when and if x >y again,
#2
Posted 26 June 2011 - 06:15 PM
//The event where you allow the trigger trigger_alowed=true
//Step event example
if (trigger_alowed==true) then {/*Do stuff here*/ ; trigger_alowed=false}
Edited by ihato, 26 June 2011 - 06:19 PM.
#3
Posted 26 June 2011 - 06:45 PM
And if the first event is in a step event it will just trigger it over and over again
for example.P-number of needet people.and I number of inhabitants allowed.
If P>I ds queue add( build,(P-I)/4).meaning that for evry one person i need a house
but it will add the number to the queue evry step...witch is a mess
i need it to add 4 to the queue just oance until P<I .then run it again if in the future P>I but again only exactly oance.
Did i make any sence?
#4
Posted 26 June 2011 - 07:08 PM
Nono - not if the variable is set to 1 only once, for instance when you press a button or in a create event.yes that s the ideea but won"t the first event just trigger the second command again?
And if the first event is in a step event it will just trigger it over and over again
//Create
var_happen = 1
//Step
if var_happen = 1
{
//do stuff
var_happen = 0
}
#5
Posted 26 June 2011 - 07:14 PM
yes that s the ideea but won"t the first event just trigger the second command again?
No, ihato's code will only run the "do stuff" coding once during that trigger event.
And if the first event is in a step event it will just trigger it over and over again
No, in a step event if nothing meets the qualifications of the "checks" or coding that is not run after a check, then the only thing that happens is that the checks are run and return values, IF THE VALUE IS NOT MET TO TRIGGER A CODE STRING THEN NOTHING ELSE HAPPENS. Sorry for the bold I am just using it to overemphasis what happens in a step event.
for example.P-number of needet people.and I number of inhabitants allowed.
If P>I ds queue add( build,(P-I)/4).meaning that for evry one person i need a house
but it will add the number to the queue evry step...witch is a mess
i need it to add 4 to the queue just oance until P<I .then run it again if in the future P>I but again only exactly oance.
Did i make any sence?
if p>i //so only if p is greater than i;
{ds_queue_add(build,(p-i)/4)} // then do this stuffSeems pretty straight forward. In that example you only do the following code when p>i, so the only time that would constantly run is IF p is always greater than i. This however is not good because until p<=i this will happen every split-second (depending on game speed) until the governing "if statement" returns a value "other than" the requisite. In the case of what I am guessing you want happen YOU HAVE TO USE A VARIABLE THAT YOU REFERENCE AS A TRIGGER AND THEN SET IT BACK AND FORTH FROM 1 TO 0 and then either set an alarm up, or code in a timer (if you know how, otherwise use an alarm) to set the variable back when you want to be able to perform the action again.
Wow. That could be too much or not well explained. I hope that helps.
#6
Posted 26 June 2011 - 07:20 PM
in create event c=0
then in step event
if c=1
{
if P>I
{ds_queue_add(build,(p-i0/4)
c=0
}
}
but where do i make c=1 again for when p.i again>?
Edited by rdt, 26 June 2011 - 07:34 PM.
#7
Posted 26 June 2011 - 09:17 PM
so something like this,
in create event c=0
then in step event
if c=1
{
if P>I
{ds_queue_add(build,(p-i0/4)
c=0
}
}
but where do i make c=1 again for when p.i again>?
Well you could set a timer or alarm to reset the variable after a set amount of time. Or there could be an event that resets it. Kinda one of those things you got to figure out yourself, because each game is vastly different and each circumstance is unique and needs to be handled according to the rules and laws of logic. So in this instance, I will assume it is an TBS or RTS where you build structures. So what I would do is, when you click to build something reset the variable "c" to 1. If my assumption is wrong just find a trigger point in your game. It's a lack of details that is preventing me from helping you fully right now.
#8
Posted 26 June 2011 - 11:15 PM
#9
Posted 27 June 2011 - 12:14 AM
Extremely rough example...
if something happens
{queue_add=building 1{c=1;}}
Edited by XxTaLoNxX, 27 June 2011 - 12:15 AM.
#10
Posted 27 June 2011 - 07:03 AM
or if someone else has a better ideea please do tell, maybe it will give me a ideea, this is my first game and first time programing, i dont know if there are specific routes to follow and so on, i just have ideeas and put it in practice with what i know:P
#11
Posted 27 June 2011 - 12:48 PM
also will trigger events that are called in a alarm be triggered each time the alarms sets off?if it s a looping alarm
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











