scriptingproblem: compare accums?!


(Maggumaster) #1

Hi@all,
I just wanted to know if it’s possible to compare 2 dynamic values with the wolfenstein script. The script should compare for example accum 1 with accum 2. I want to make a demonstrationmap how “bubblesort” works. So i need some variables to be compared. Here’s a part from the script, that doesn’t work:

trigger position1
{
trigger position1excheck
accum 1 abort_if_bitset 1
trigger self position 2
}
trigger position1excheck
{
accum 1 abort_if_less_than accum 2// problem?! :bash:
accum 1 bitset 1
trigger self position1exchange
}

trigger position1exchange
{
trigger Block1 exchangeforw
trigger Block2 exchangebackw
wait 2000
accum 1 inc 1
accum 2 inc -1
trigger self positon2

}

You see, this is not possible with the given scripting commands, isn’t it? Any ideas?

greetz
Maggumaster


(The Wanderer) #2

It is possible to do what you’re saying… although it’s not very straight forward
Try something like the following. I didn’t test this and it only works with positive values (and there are probably a bunch of syntax mistakes) but it should give you some idea on how to go about doing it.
Basically the compare function compares accum 1 and accum 2 and it stores the result in
accum 0. The result is:
-1 if accum 1 < accum 2,
0 if accum 1 == accum 2 and
1 if accum 1 > accum 2
accum 3 is used as a temporary variable and its contents are destoryed. accum 1 and 2 are preserved.


trigger compare
{
	accum 3 equal 0
	trigger calculate_results
	trigger store_results
	trigger restore_values
}


trigger calculate_results
{
	accum 1 abort_if_equal 0
	accum 2 abort_if_equal 0
	accum 1 inc -1
	accum 2 inc -1
	accum 3 inc 1
	trigger calculate_results
}

trigger store_results
{
	accum 0 set 0
	accum 1 trigger_if_equal 0 less_then
	accum 2 trigger_if_equal 0 greater_then
}

trigger restore_values
{
	accum 3 abort_if_equal 0
	accum 1 inc 1
	accum 2 inc 1
	accum 3 inc -1
	trigger restore_values
}

trigger less_then
{
	accum 2 abort_if_equal 0
	accum 0 set -1
}

trigger greater_then
{	
	accum 1 abort_if_equal 0
	accum 0 set 1
}


(]UBC[ McNite) #3

Can you give a bit more info about what you need the comparison for? Maybe there s a simpler approach/ solution to what you want to get.


(Maggumaster) #4

It’s for a small demonstrationmap, to show how bubblesort works. Bubblesort is a simple program, that sorts lists in a very simple way. Like this:
You have a list of numbers, for example:
12, 4, 5, 9, 6

The program looks at the first number, compares it with the second, and if it’s bigger, it exchanges the numbers. So the list looks like this now:
4, 12, 5, 9, 6

Now it compares number 2 with number 3 and exchanges them, if 3 is bigger… The program repeats this process until there are no more exchanges. So the list will look like this in the end:
4, 5, 6, 9, 12

I want to demonstrate this process with different blocks in a wolfenstein map.
Thx2 the wanderer, Your suggestion is very interessting and will try to impliment it. I’ll post here if i have success with your method.

greetz,
Maggumaster