accum toggle question


(tsakali) #1

my proplem is this: without the use of IF statements, my understanding of logic goes out the window.

how do I effectively use an accum to be able to toggle somethign off and on …but not just one way I want it to work both ways so it can be re-usable.

here is my script:

propturn
{
 spawn
 {

   accum 1 set 1
   wait 200
 }


 trigger proprotate
 {

 trigger propturn spin

 trigger propturn stop
togglespeaker target_speaker

 }


trigger spin
{

accum 1 abort_if_not_equal 0   
accum 1 set 0

trigger propeler spin

}




trigger stop
{
accum 1 abort_if_not_equal 1  // 0=spining
accum 1 set 1
trigger propeler stop

}




}

/////////////////////////////////

propeler
{
 spawn
 {

 }

trigger stop
{
stoprotation
}




trigger spin
{
setrotation 0 1000 0

}

}

obviously, no matter the accum, if this script was to run it goes through both “trigger stop” and “trigger spin” . because “trigger spin” will always change the accum before “trigger stop” gets a chance to evaluate, in effect the choices between spin and stop don’t work out

I know this is a very simle script but I just can’ t figure out how to get it to work


(kamikazee) #2

You seem to be confused in what abort_if_… does or you confuse accum1’s meaning

accum 1 abort_if_not_equal 0

This command will stop the current trigger from running if accum1 != 0.
So, to continue, it must be 0. Next step of your spin trigger: (propturn block)

accum 1 set 0

Here you’re setting accum1 to zer0, even though it allready was zero.
Now, let’s attach a purpose to accum1: if it’s 1, it’s stopped. If it’s 0, it’s spinning. (It’s allso handy to put this text as comments in your propturn code block so you now what’s accum1 used for)
Now you only need to change the first steps in the triggers of propturn:

accum 1 abort_if_not_equal 0

Must simply be changed to

accum 1 abort_if_not_equal 1

(You can read this now as: if (accum1 != 1) abort; else { //rest of script }


(Ifurita) #3

You can also use a trigger_if_equal structure. This is what I put together for the tactical map, to create random movement of my targets



target1
{
	spawn
	{
		wait 100
		trigger target1 loop
	}

	trigger loop
	{
		accum 0 random 4
		accum 0 trigger_if_equal 0 target1 point1
		accum 0 trigger_if_equal 1 target1 point2
		accum 0 trigger_if_equal 2 target1 point3
		accum 0 trigger_if_equal 3 target1 point4
	}

	trigger point1
	{
		gotomarker target1_1 90 wait
		trigger target1 loop
	}

	trigger point2
	{
		gotomarker target1_2 90 wait
		trigger target1 loop
	}

	trigger point3
	{
		gotomarker target1_3 90 wait
		trigger target1 loop
	}

	trigger point4
	{
		gotomarker target1_4 90 wait
		trigger target1 loop
	}

	pain 
	{
		playsound sound/tactical/hit.wav
	}

	death
	{
		wm_announce "target 1 destroyed"
		trigger game_manager target_counter
		trigger self reset
	}

	trigger reset
	{
		setstate target1 invisible
		wait 15000
		setstate target1 default
		alertentity target1
		trigger target1 loop
	}	
}


(tsakali) #4

k I made changes to your recomendation , and yes I did make some mistakes on my first posted code but I still don’t see how this will overcome the logic problems since one of them will always be avaluated before the other hence affecting the input of the second

]
propturn
{
 spawn
 {

   accum 1 set 1   // 1 means it is already spining

 }


 trigger proprotate
 {

 accum 1 trigger_if_equal 0 propturn spin  // if it is 0 meaning not spinning then trigger the spin and change it to 1
                                           
 accum 1 trigger_if_equal 1 propturn stop

togglespeaker target_speaker

 }


trigger spin
{
accum 1 set 1
trigger propeler spin
}


trigger stop
{
accum 1 set 0 // 0=spining
trigger propeler stop
}

}

/////////////////////////////////

propeler
{
 spawn
 {

 }

trigger stop
{
stoprotation
}




trigger spin
{
setrotation 0 1000 0

}


can someone just please make the changes right in my script so I can clearly see what day it is :banghead:


(kamikazee) #5

Man, you are seriously messing it up…

You actually say in your stop trigger:
accum 1 set 0 // 0 = spinning
You should put it to 1 as you’re just stopping the spinning!

To ease your pain: here’s the code. Study it before you copy it in your script file.

EDIT: Made a mistake myself, sorry! (Fixed now)

propturn
{
    spawn {
        accum 1 set 1   // 1 means it is already spining
    }

    trigger proprotate {
        accum 1 trigger_if_equal 0 propturn spin  // 0-> stopped
        accum 1 trigger_if_equal 1 propturn stop // 1-> spinning
        togglespeaker target_speaker
    }

    trigger spin {
        accum 1 set 1
        trigger propeler spin
        //do not go back to proprotate
        resetscript
    }

    trigger stop {
        accum 1 set 0 // 1=spinning
        trigger propeler stop
        //do not go back to proprotate
        resetscript
    }
}

/////////////////////////////////

propeler
{
    spawn {
        wait 300
     }

    trigger stop {
        stoprotation
    }

    trigger spin {
        setrotation 0 1000 0
    }
} 

(tsakali) #6

thanx for the help, actually the command to reset script is really what I needed.

ohh and you got the accum values mixed up heh, thanx again


(kamikazee) #7

Ah yes, now I mixed them myself since I looked at the comments in your previous code…
I should have stripped those and remade it from scratch…

I’ll fix it.


(tsakali) #8

no need