Multiple moving components scripting problem.


(MadJack) #1

My Mobile Flak 88 again :smiley:

I have adapted the goldrush tank routine to my Mobile Flak and it works great as far as I stay with the basics of tank stuff.

Unfortunately, the flak is a lot more complicated than the tank.

There are some conditions that, if they apply, will stop the tank from moving. If the feet are down, the turret is not facing the front and the cannon is not down will stop the tank from moving.

My problem is that everything is working if I don’t push a button to activate something while there is a part moving.

In more details.

The test map has buttons to move the parts up/down/left/right so I can test if everything is working. Now, if I push the button to move a leg up/down and wait until it finishes, everything is fine. But if I activate a button while there’s already something moving everything after the ā€œwait 5000ā€ is skipped basically breaking the script, not setting stuff.

There’s probably a better way to do it but it seems I’ve been working on it too much and became blind to other ways of doing it.

Help would be appreciated.

Here’s the left foot part in mflak{} scriptblock as an exemple:

This bit is used to move the left foot up/down.


	trigger lfoot_check_move // check for moving flak88 left foot up/down
	{
		accum 1 abort_if_bitset 7 // are we dead?
		accum 6 abort_if_bitset 1 // if foot already moving
		globalaccum 1 abort_if_not_equal 0	// scriptlock'ed out?
		trigger mflak lfoot_check_move_up
		accum 6 abort_if_bitset 2 // if just moved up
		trigger mflak lfoot_move_down
	}

	trigger lfoot_check_move_up
	{
		accum 6 abort_if_bitset 0 // already up
		trigger mflak lfoot_move_up
	}

	trigger lfoot_move_up // move the flak88 left foot up
	{
		trigger left_foot lfoot_lockout // set script locked out
		accum 6 bitset 1 // it's moving
		trigger left_foot up
		wait 5000
		accum 6 bitset 0  // tag it up
		accum 6 bitreset 1 // done moving
		trigger left_foot lfoot_lockout_stop // unset script locked out
	}

	trigger lfoot_move_down // move the flak88 left foot down
	{
		trigger left_foot lfoot_lockout // set script locked out
		accum 6 bitset 1 // it's moving
		trigger left_foot down
		wait 5000
		accum 6 bitreset 0 // tag is down
		accum 6 bitreset 1 // done moving
		trigger left_foot lfoot_lockout_stop // unset script locked out
	}

The left_foot stuff…


left_foot
{
	spawn
	{
		wait 175
		globalaccum 1 set 0
		attachtotag mflak tag_leftf
	}
	
	trigger down
	{
		faceangles 0 0 0 5000 
	}
	
	trigger up
	{
		faceangles 0 0 85 5000
	}

	trigger lfoot_lockout
	{
		globalaccum 1 inc 1
	}
	
	trigger lfoot_lockout_stop
	{
		globalaccum 1 inc -1
	}
}

The script is nicely commented and easy to follow I think so I’ll refrain from commenting it more. As I said above, if I activate the right foot while the left foot is moving, the lines after ā€œwait 5000ā€ in the left foot won’t be read. Breaking the whole left foot routine since accums are not set/reset.

Ideas and suggestions?

Thanks in advance.


(Mr_Tickles) #2

Ummm, you could possibly merge the two legs into just the one entity to get rid of the problem.


(MadJack) #3

Nope, no can do. Each leg has to be its own entity because each can be moved and they have to be referenced as their targetname/scriptname. If I merged them or with the mflak scriptblock, it’ll be both the feet that will move at the same time or the whole mflak.

On top of that, there’s still the turret and the cannon that has to be considered as each part’s movement is dependent of the placement of some or all the others.


(No1_sonuk) #4

Maybe you should use bit setting/clearing on the globalaccum instead of incrementing. That could be were your script is getting lost.


(MadJack) #5

The thing is that I tried to move the wait 5000 to different places but it seems that if a button call is made it will stop anything after the wait 5000 to be interpreted so that I set/reset it doesn’t matter because it will abort before hitting that line. So in that case it would stay set and subsequently be unable to enter the function.

There has to be a way to do it so it won’t abort after the wait is done.


(No1_sonuk) #6

Take the wait out. Use a globalaccum, and put the flags in the movement routines.


(MadJack) #7

IMO the wait has to be there because the flags have to be set/reset when the foot hit the ground or is done going up. It takes 5 secs to go up/down and if I don’t set it to wait, it’ll be set/reset immediately making it possible to press the button while in movement.

I thing it would work I agree, but I’d prefer if it couldn’t be moved again until it either went down or up. Though I’ll have to consider that alternative…


(chavo_one) #8

You need to read this thread MadJack.
http://www.splashdamage.com/index.php?name=pnPHPbb2&file=viewtopic&t=4476&highlight=

Waits can have nasty effects if used in the wrong situations and places. Be aware that ā€œresetscriptā€ is a synonym for ā€œwait 50ā€. So every characteristic of ā€œresetscriptā€ is a characteristic of a ā€œwaitā€.


(MadJack) #9

Thanks chavo_one. Nice reading. :slight_smile:

The problem though, is not with the fact that it doesn’t come back to the calling block, it just won’t read the lines following the wait IF I activate the other leg’s button while it moves.

Maybe that will be clearer:

If I click to activate the left leg, it’ll move up and set/reset its stuff (position is now up, it’s done moving etc). Then I activate the other leg, it goes up, do its things etc. If I click on that leg again, it’ll go down, sets itself correctly etc. But if I somehow interrupt one leg by activating the other leg while it’s waiting, the one waiting won’t run the lines after the wait.

I’m thinking about moving the whole leg moving parts in each foot’s scriptblock but I’m afraid it might just do the same thing… Anyway, I’ll just make a backup and try that. Who knows, it might just work. Downside to this is that I’ll have to use globalaccums… But if that’s the price to pay, I’ll pay it.


(FireFly) #10

Well, i’'m just brainstorming here but perhaps one solution would be that you disable the other buttons while one is activated, so the routine in the script won’t be interrupted.And once the routine is finished all buttons will be enabled again…For example with ā€˜setstate’ make the other buttons temporarely invissible…


(No1_sonuk) #11

what I meant was that you put the wait in the leg moving code, like this:

trigger down 
   { 
// Put the flags stuff here

      faceangles 0 0 0 5000 wait

// Put the flags stuff here

   } 


(MadJack) #12

@ no1_sonuk. Funny how we copy/paste stuff from other scripts expecting things to work :slight_smile: the wait statement at the end of faceangles isn’t in the source. I was about to answer to your post telling you that it wasn’t making an difference and I though to check to make sure I got it right. So yeah, wait is not even in the params… No wonder it wasn’t making any differences.

Syntax is as the LDR says: faceangles <pitch> <yaw> <roll> <duration/GOTOTIME> [accel/decel]

@ FireFly, yeah… I’ve already made it work in a similar fashing by using an accum. I would prefer to leave the ability to move it up/down independently if it’s possible. If everything fails I’ll have to either make them move at the same time or block one while the other is moving.

Thanks again for all suggestions/ideas.


(MadJack) #13

Finally!!!

Made it work but not as I wanted to do it in the first place… :frowning: Oh well… as long as it works. Here’s what I did.

First, whereever I put the wait 5000 it would just skip the lines following if I interrupted it. So I decided to make both feet move at the same time… Didn’t work either, it would do the same thing. If I’d push the button while it was moving, it’d skip the lines.

I thought hard and long… The idea came to me as I wondered how I could make the whole thing wait 5 seconds. Of course! func_timer :slight_smile:

For those interested, here are the important parts of the script.


	trigger feet_move // move the flak88 right foot up/down
	{
		accum 1 abort_if_bitset 7 // are we dead?
		accum 7 abort_if_bitset 2 // if locked out
		accum 7 bitset 2	// lock out
		trigger mflak feet_check_move_up
		accum 7 abort_if_bitset 3 // if just moved up
		trigger mflak feet_move_down
	}

	trigger feet_check_move_up
	{
		accum 7 abort_if_bitset 0 // already up
		trigger mflak feet_move_up
	}

	trigger feet_move_up // move the flak88 right foot up
	{
		accum 7 bitset 2 // just moved
		trigger mflak feet_up
		accum 7 bitset 0 // tag it up
	}

	trigger feet_move_down // move the flak88 left foot down
	{
		accum 7 bitreset 0 // tag it down
		trigger mflak feet_down
	}

	trigger feet_up
	{
		trigger left_foot up
		trigger right_foot up
		accum 7 bitset 3
	}

	trigger feet_down
	{
		trigger left_foot down
		trigger right_foot down
		accum 7 bitreset 3
	}

	trigger feet_count
	{
		accum 7 abort_if_not_bitset 2 // abort if not locked out
		accum 6 inc 1				// up the stop counter
		accum 6 abort_if_less_than 5	// count to 5 (time to move those feet)
		accum 6 set 0	// reset counter
		accum 7 bitreset 2	// unlock
		accum 7 bitreset 3	// didn't move just yet
	}

The right foot is the same as the left so no need to post that…


left_foot
{
	spawn
	{
		wait 175
		attachtotag mflak tag_leftf
	}

	trigger down
	{
		faceangles 0 0 0 5000
	}

	trigger up
	{
		faceangles 0 0 85 5000
	}
}


(No1_sonuk) #14

OK, maybe the ā€œwait 5000ā€ and flags thing needs to be in the movement routines.


(MadJack) #15

I tried that. Same results. If it’s interrupted, it’ll skip the lines after the wait.

I moved the whole moving and checking out of the main part so it would be done independently and it gives the same results.