Escalator

Post your scripting questions / solutions here

Moderator: Moderators

User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Escalator

Post by tltrude »

I'm trying to get an escalator to work, but so far it just locks up on map load when I try to use the threads below. Any help would be great!!!

Code: Select all

//----------------------------------------------------------->
// Escalator threads
//----------------------------------------------------------->

escalator_prep:

	$step1 moveDown 256
	$step1 waitmove
	$step1.count = 0
	$step2.count = 1
	$step3.count = 2
	$step4.count = 3
	$step5.count = 4
	$step6.count = 5
	$step7.count = 6
	$step8.count = 7
	$step9.count = 8
	$step10.count = 9
	$step11.count = 10
	$step12.count = 11
	$step13.count = 12
	$step14.count = 13
	$step15.count = 14
	$step16.count = 15
	$step17.count = 16

goto escalator_mover

escalator_mover:

	wait .5
	$step1 thread movemeup
	$step2 thread movemeup
	$step3 thread movemeup
	$step4 thread movemeup
	$step5 thread movemeup
	$step6 thread movemeup
	$step7 thread movemeup
	$step8 thread movemeup
	$step9 thread movemeup
	$step10 thread movemeup
	$step11 thread movemeup
	$step12 thread movemeup
	$step13 thread movemeup
	$step14 thread movemeup
	$step15 thread movemeup
	$step16 thread movemeup
	$step17 waitthread movemeup


goto escalator_mover

end

movemeup:

	if (self.count == 16)
		{
		self moveWest 16
		self waitmove
		self.count ++
		}
	if (self.count == 17)
		{
		self moveto $step_way1
		self waitmove
		self moveto $step_way2
		self waitmove
		self.count = 0
		goto escalator_mover
		}
	self moveUp 16
	self moveWest 16
	self waitmove
	self.count ++

end
The 17th step (top step) has to move west 16 and then move to the empty spot where step one was--below the ground. There is probably a better way of doing this, so any wild ideas are welcome, ha ha.
Last edited by tltrude on Mon May 05, 2003 3:48 pm, edited 2 times in total.
Tom Trude,

Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

maybe, it's because a step with count 16 will go through 1st if clause, gets count 17, go therefore through 2nd if clause, gets count 0, then also through the rest, coming out with count 1, so you won't have steps with count 0, at least not very long... don't know whether this is a problem?

just an idea :oops:

movemeup:
if (self.count == 17)
{
self moveto $step_way1
self waitmove
self moveto $step_way2
self waitmove
self.count = 0
}
if (self.count == 16)
{
self moveWest 16
self waitmove
self.count ++
}
if (self.count<16 and self.count>0) //don't know whether this is correct!?
self moveUp 16
self moveWest 16
self waitmove
self.count ++

end


may I use it in my shopp, when it's done? :wink:
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

goto escalator_mover

This line (the 2nd time it appears) causes a command overflow and makes your script crash back to the main menu. This is because you're looping your code without waiting for anything, thus the steps get a command to move again before they've finished their previous move.

Maybe this will work better:

Code: Select all

(...)
   $step14 thread movemeup 
   $step15 thread movemeup 
   $step16 thread movemeup 
   $step17 waitthread movemeup 


goto escalator_mover 
In this case, all steps wait until step17 has reached its destination. Then all steps move again to their next position.
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

crashing fixed

Post by tltrude »

Ok, jv_map's code stopped the crashing, but the counters must not be working. The steps just keep going up into outerspace.
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Why not make a special debug version of movemeup: ? Then make $step1 use this debug version instead.

The debug version could print useful texts like the current count value to the screen or console (output to screen has a slight delay so it's not very accurate).
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Brains

Post by tltrude »

I just need a new brain. Turned out to be spelling errors in the map.

stap_way1
stap_way2

It works now--only minor adjustments left. Thanks jv_map!!

Ps: Wacho - I will post the escalator as part of my explodingdoor tutorial map. I decompiled your Shopp bsp and copied your escalator, but it had a lot of missing brushes. So, I had to rebuild the whole thing. Anyway, you are welcome to the script, and thankyou for making such a great map!

The script in the first post has been edited.
Tom Trude,

Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

:D I'm looking forward to it!

I was playing around with your script (and my ideas :? ) but it ended in a error 'Bad Token' for a moveUp line.
Now with your new script, the steps are moving, but some wait some move, they get mix up, gather somewhere and so on. Where should I set the info_waypoints? Well, I'll see in your tut map...

Btw, is thre a way to let script_objects 'jump' to another waypoint and/or to change the speed they're moving?
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Out of sync

Post by tltrude »

Well, I was wrong. It needed more than minor adjustments. The steps were out of sync and were all over the place. But, I did finally get it working with the script below. There is one step that moves funny (bobs), but it is not very noticeable. I will post the map here when I get it final compiled. Here is part of the script--it's very long now.

Code: Select all

//----------------------------------------------------------->
// Escalator threads
//----------------------------------------------------------->

escalator_prep:

	$step1 moveDown 256
	$step1 waitmove
	$step1.count = 0
	$step2.count = 1
	$step3.count = 2
	$step4.count = 3
	$step5.count = 4
	$step6.count = 5
	$step7.count = 6
	$step8.count = 7
	$step9.count = 8
	$step10.count = 9
	$step11.count = 10
	$step12.count = 11
	$step13.count = 12
	$step14.count = 13
	$step15.count = 14
	$step16.count = 15
	$step17.count = 16

goto escalator_mover

escalator_mover:

	wait 2
	thread move1
	thread move2
	thread move3
	thread move4
	thread move5
	thread move6
	thread move7
	thread move8
	thread move9
	thread move10
	thread move11
	thread move12
	thread move13
	thread move14
	thread move15
	thread move16
	thread move17

end

move1:

while (1)
	{
	wait .1
	if ($step1.count == 16)
		{
		$step1 speed 64
		$step1 moveWest 16
		$step1 waitmove
		$step1.count ++
		}
	if ($step1.count == 17)
		{
		$step1 speed 2048
		$step1 moveto $step_way1
		$step1 waitmove
		$step1 moveto $step_way2
		$step1 waitmove
		$step1.count = 0
		}
	if (($step1.count != 16) || ($step1.count != 17))
		{
		$step1 speed 64
		$step1 moveUp 16
		$step1 moveWest 16
		$step1 waitmove
		$step1.count ++
		}
	}
	waitframe

end

move2:

while (1)
	{
	wait .1
	if ($step2.count == 16)
		{
		$step2 speed 64
		$step2 moveWest 16
		$step2 waitmove
		$step2.count ++
		}
	if ($step2.count == 17)
		{
		$step2 speed 2048
		$step2 moveto $step_way1
		$step2 waitmove
		$step2 moveto $step_way2
		$step2 waitmove
		$step2.count = 0
		}
	if (($step2.count != 16) || ($step2.count != 17))
		{
		$step2 speed 64
		$step2 moveUp 16
		$step2 moveWest 16
		$step2 waitmove
		$step2.count ++
		}
	}
	waitframe

end

etc... etc... etc...
It might work using the "while" with "self", but I haven't tried it.
Tom Trude,

Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

What I do not understand:
if (($step2.count != 16) || ($step2.count != 17))
means if $step2.count is not 16 or is not 17 then do something!?
Which step could have a count that is not not 16 or not 17?
count--cond1--cond2--total
0...........1..........1........1
2...........1..........1........1
...
16.........0..........1........1
17.........1..........0........1, so the result is always 1
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

safty

Post by tltrude »

You are right, any step that does not (!=) have a count of 16 or (||) does not have a count of 17 will just move up. It would probably work fine without that line--I put it in for safty because steps were getting count of 18 and higher.

Any line that say:

$stepX.count ++

adds one to the count that was first set in "prep" for that step. Because it is in a "while" loop, it keeps adding one everytime the step moves. When it gets to 16, the step moves west only (at the top) and, when it gets to 17, it shoots back down to the bottom of the stack where its count is reset to zero.

I think jv_maps is right about goto loops being bad for complex threads. But then, he is always right!!! :)
Tom Trude,

Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post by wacko »

So the script - when you say, it comes to counts of 18 - isn't working correctly? :shock: The script skips lines? :shock: :shock: That would be a good reason for my escalator trials behaving so strange. Or do you see s/th completely wrong:

Code: Select all

main:
	level waittill spawn
	thread escalator_prep
end
//-----------------------------------------------------------> 
// Escalator threads 
//-----------------------------------------------------------> 
escalator_prep: 
   $step1 speed 1000
   $step1 moveDown 256 
   $step1 waitmove
   $step17 speed 1000
   $step17 moveDown 16
   $step17 waitmove
// My steps are probably positioned different
   $step1.count = 0 
   $step2.count = 1 
   $step3.count = 2 
   $step4.count = 3 
   $step5.count = 4 
   $step6.count = 5 
   $step7.count = 6 
   $step8.count = 7 
   $step9.count = 8 
   $step10.count = 9 
   $step11.count = 10 
   $step12.count = 11 
   $step13.count = 12 
   $step14.count = 13 
   $step15.count = 14 
   $step16.count = 15 
   $step17.count = 16 
goto escalator_mover 
end
escalator_mover: 
   $step1 thread movemeup 
   $step2 thread movemeup 
   $step3 thread movemeup 
   $step4 thread movemeup 
   $step5 thread movemeup 
   $step6 thread movemeup 
   $step7 thread movemeup 
   $step8 thread movemeup 
   $step9 thread movemeup 
   $step10 thread movemeup 
   $step11 thread movemeup 
   $step12 thread movemeup 
   $step13 thread movemeup 
   $step14 thread movemeup 
   $step15 thread movemeup 
   $step16 thread movemeup 
   $step17 waitthread movemeup
goto escalator_mover 
end 

movemeup: 
   if (self.count == 16) 
      { 
      self speed 64
      self moveDown 256
      self moveEast 272
// I kicked the waypoints...
      self waitmove 
      self.count = 0 
      goto move_end
      }
   if (self.count == 15) 
      { 
      self speed 64
      self moveWest 16 
      self waitmove 
      self.count ++
      goto move_end
       }

   self speed 64
   self moveUp 16 
   self moveWest 16 
   self waitmove 
   self.count ++  
move_end:
end
This seems to end up in lots of steps with the same count :cry:

And: isn't there a way to make s/th like this:

Code: Select all

for (i < 17)
  {
  $step(i)...
  i ++
  }
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Array

Post by tltrude »

I had it like you have it now and had the same problems. I think it is because there were too many threads trying to use the same "self" code. Although I did not try it with the "while" line and brackets, I suspect it would be just as bad. A lot of it has to do with timing and how long it takes a step to get back to the bottom.

Here is a link to download my updated Exploding Door Tutorial map:

http://pages.sbcglobal.net/tltrude/Temp ... ngdoor.zip

You are welcome to use anything you like from it. Maybe you can get the escalator working better, now that we at least have it moving somewhat normally!
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Wacko is right, if (($step2.count != 16) || ($step2.count != 17)) always returns 1, unless the count would be both 16 and 17 :?. Unless you're into quantum mechanics, that's never the case ;).

It seems a good idea to use some for statements, which could reduce the code drastically. For example, the escalator_prep: could also be written like this:

Code: Select all

escalator_prep:
   $step1 moveDown 256
   $step1 waitmove
   // local.i will be the step number
   for(local.i = 1; local.i <= 17; local.i++)
   {
      local.step = $("step" + local.i)
      local.step.count = local.i - 1
   }
end
If you don't understand the for statement, read Bjarne's scripting tutorial inside the sticky on top of this forum.
Image
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Tired

Post by tltrude »

I'm tired of futsing with it. Download my tutorial and make it run smooth!

expr || expr Logical or, if at least one of the expressions is true ( 1 ): output 1, else 0

expr != expr Inequality, if the 2 expressions have different values: output 1, else 0
Tom Trude,

Image
User avatar
bdbodger
Moderator
Posts: 2596
Joined: Tue Feb 25, 2003 7:34 am
Location: canada
Contact:

Post by bdbodger »

Just an idea I had might help
level.topstep1=$step1.origin
level.topstep2=$step2.origin
level.steps=16

escalator:
for(local.i=1;local.i<level.steps+1;local.i++)
{
local.movestep = $("step"+local.i)
if (local.movestep.origin==level.topstep2)
{
local.movestep speed 64
local.movestep moveWest 16
local.movestep waitmove
goto nextstep
}
if (local.movestep.origin==level.topstep1)
{
local.movestep speed 64
local.movestep moveDown 256
local.movestep moveEast 272
local.movestep waitmove
goto nextstep
}
local.movestep speed 64
local.movestep moveUp 16
local.movestep moveWest 16
local.movestep waitmove

nextstep:
}
goto escalator
end
of course you have to put $step1 beside $step2 at the top of the escalator
Post Reply