Scripting help - accum


(evillair) #1

Can someone please give me the rundown on the accum meanings?

The LDR mentions these but I’m having a bit of trouble knowing what they do and how to use them.

(global)accum <buffer_index> <command> <<paramater…>
(global)accum <n> inc <m>
(global)accum <n> abort_if_less_than <m>
(global)accum <n> abort_if_greater_than <m>
(global)accum <n> abort_if_not_equal <m>
(global)accum <n> abort_if_equal <m>
(global)accum <n> set <m>
(global)accum <n> random <m>
(global)accum <n> bitset <m>
(global)accum <n> bitreset <m>
(global)accum <n> abort_if_bitset <m>
(global)accum <n> abort_if_not_bitset <m>
(global)accum <n> trigger_if_equal <m> <s> <t>
(global)accum <n> wait_while_equal <m>
cvar <cvarName> <operation> <value>
Operation can be any of:
inc
abort_if_less_than
abort_if_greater_than
abort_if_not_equal
abort_if_not_equals
abort_if_equal
abort_if_equals
bitset
bitreset
abort_if_bitset
abort_if_not_bitset
set
random
trigger_if_equal
wait_while_equal

Thanks in advance.

I just need someone to give me a rough idea of what they are used for.

Thanks.


(SCDS_reyalP) #2

Accum is like a register or variable. They are identified by a number, from 0 to some maximum. You can put a 32 bit integer value into it (either as a number or as single bits) and then do various things based on that value. So for example, if you had a scripted drawbridge, you could use one bit of an accum to keep track of whether it was raised or lowered.

the cvar commands seem to let you do the same thing, only with a cvar. I assume that you can only change server cvars this way, though I haven’t tested it :P. In RTCW, this only worked in SP (if I remember right). It certainly has interesting possibilities if it works in ET MP. For example, having a game event change g_gravity.

As in RTCW, accums are specific to each entity. So accum 1 in game_manager would be different from accum 1 in your drawbridge script_mover entity. ET (unlike RTCW) also has global accums, which not attached to any entity. This is vary handy for sharing information between entities. Because (non-global) accums are per entity, any trigger belonging to that entity gets the same set of accums.

Another side effect of accums being per entity (in RTCW at least) was that if you have more than one entity with the same scriptname, each one would get its own set of accums, even though they used the same script. This often lead to results the mapper did not expect.

The abort… commands stop execution of that trigger if the condition is met.

set puts the specified value in the accum.
bitset turns on (sets to 1) the specified bit (numbered from 0 to 31)
bitreset turns off (sets to 0) "
random puts in a random value, up to (probably including) the specified number.

inc adds the specified value. Use a negative value to subtract.

Hopefully djbob or sock will flame me if I got any of this wrong, I’m mostly going by what I remember from RTCW.


(Lanz) #3

Accums are used to store variables in scripts, it’s used for all sorts of things like keeping track if a wall is blown, or if like in my map silly ctf 3 gold crates has been stolen from one team.

Ex.
accum 0 set 5

This says set accum 0 to the value 5.

Ex.
accum 0 inc 1
This would increase the value of accum 0 with 1, in this case to 6 (as it’s set to 5 in the previous example).

the abort_if_* just affects the execution of the script depending on the value of the accum:

Lets assume that accum 0 is set to 5:
accum 0 abort_if_less_than 6 – yes, it’s less than 6, abort the script.
accum 0 abort_if_greater_than 6 – Nope, it’s not continue.

One more example:

trigger axis_secured
{
accum 0 trigger_if_equal 1 game-manager axis_secured1
accum 0 trigger_if_equal 2 game_manager axis_secured2
accum 0 trigger_if_equal 3 game_manager axis_secured3
}

In my map mp_sillyctf I just count the gold crates, if axis secure the first crate, accum o is set to 1. trigger_if_equal checks if the value of the accum is equal to the operator in the script, as the first one, the value 1. If it is, it runs the trigger defined and in this case that one contain the message that axis has captured the first gold crate.

Ok, this was just some simpe info that I hope will help, just ask if there’s still something you wonder about.


(evillair) #4

Thanks guys, I think got it.


(Doc) #5

I have a question about accums: Is it possible to compare two accums (or a globalaccum)? I’m trying to script a convoy of 3 trucks where they may get separated, and I’m having trouble getting truck2 to stop if truck1 is in front of it. If there is a way to abort_if_not_equal another accum this would be easy. My testing suggests there isn’t. Is there any way? I don’t want to be forced to make a 20000 line script…


([rD]MrPink) #6

Have you tried accum 0 abort_if_not_equal accum 1, or something along those lines?


(Irrelevant) #7

Does scripting have labels and jumps? If so, this (pseudocode) would work for conditional structures:

‘if’ structure:


accum 0 jump_if_not_equal accum 1 [end_if]

...

label [end_if]

‘if… else’ structure:


accum 0 jump_if_not_equal accum 1 [else]

...

jump [end_if]
label [else]

...

label [end_if]

[edit]
Actually, that wasn’t quite what you were looking for. Ignore me.


(damocles) #8

The only way I can think of making truck stop if one is blocking it is to set up a global acuum and use it’s bits (32 of em) to register if a truck is “on” a path corner. This is a pin to set up, but if you look at railgun, you can see the huge scripting they had to do just to get one tug moving!

So basically, divide the script up into lots of gotomarker sections that also set the global acumm bits that correspond to that path corner. If the bit is already on then the truck cannot continue to that point. When it leaves that point for the next, set the bit to off.

If you have more than 32 path corners then you’ll have to use a second globalaccum too.

You’ll also need a truck “move” function that keeps an accum value telling it which corner to be moving too. Alas the only way to do this is to have 32 trigger_if_equal statements.

It’s not difficult to make just time consuming and if you make a mistake, it’ll be a pain in the ass to find it :confused:


(Mean Mr. Mustard) #9

You could also call a trigger from the truck1 script part that sets an accum of truck2. So, when truck1 stops ‘trigger truck2 stop_me’ which would set an accum to a value. This value can then be checked against and used to stop truck2


(damocles) #10

The only problem there is if the trucks are far apart, then all the Axis have to do is stop the first truck and all three would stop regardless of how far they are apart.


(Mean Mr. Mustard) #11

Very good point! (I’m was thinking in terms of bridges…) Ignore my suggestion…


(Ragnar_40k) #12

Nope. But you can get around it by creating additional triggers, e.g. if you want to check if accum 0 is greater then 10:

a0 := m
If a0 > 10 Then
    // If branch
    // actions for a0 > 10
Else
    // Else branch
    // actions for a0 <= 10
Fi
// additional actions go here

will translate to:

trigger condition
{	
    accum 0 set <m>
    trigger self if_branch
    trigger self else_branch
    // additional actions go here
}

trigger if_branch
{    
    accum 0 abort_if_less_than 10
    // actions for a0 > 10
}

trigger else_branch
{
    accum 0 abort_if_greater_than 9
    // actions for a0 <= 10
}

(Ragnar_40k) #13

You can add two vars for each truck: one where it actually is located (you should already this var to keep track of your “run_xxx” triggers) and one to show how far (to which spline segment) it can move w/o getting blocked. So when the leading truck is moving and its location accum is increased, you also increase the blocking accum for the second truck to show how far (up to which segment) it can move w/o colliding. And when the second truck is about to move the blocking accum is checked with a “abort_if_less_than” command inside the resp. “run_xxx” trigger if it can move. I suggest that truck_2 stays always at least 2 segments behind truck_1 to be on the safe side.

truck_1
{    
    .
    .
    .
    trigger run_122
    {    
        followspline ...
        trigger truck_2 truck_1_moved  // Set blocking accum for the following truck.
        trigger self run_continue      // Increase location accum and do other stuff.
    }

    trigger run_123
    {    
        followspline ...
        trigger truck_2 truck_1_moved  // Set blocking accum for the following truck.
        trigger self run_continue      // Increase location accum and do other stuff.
    }
    .
    .
    .
}

// accum 7 will show where truck_1 is right how.
truck_2
{
    .
    .
    .
    trigger run_122
    {
        accum 7 abort_if_less_than 124  // truck_2 can only move when truck_1 is at least within segment 124.
        followspline ...
        trigger self run_continue       // Increase location accum and do other stuff.
    } 
    trigger run_123
    {    
        accum 7 abort_if_less_than 125  // truck_2 can only move when truck_1 is at least within segment 125.
        followspline ...
        trigger self run_continue       // Increase location accum and do other stuff.
    }

    trigger truck_1_moved
    {
        accum 7 inc 1                   // truck_1 moved to next segment
    }
    .
    .
    .
}

(Doc) #14

Thanks, Ragnar. I actually thought of this myself today, implemented it, saw that it worked, then checked the forum. Pity accum math is so limited, but this method will do the job.


(SiliconSlick) #15

Just tried it… added the following to a triggered event:

                cvar g_gravity abort_if_not_equal 800
                wm_announce "gravity is normal... "
                cvar g_gravity set 200
                cvar g_gravity abort_if_equal 200
                wm_announce "and there is nothing that can be done about it"

And on the console I get “gravity is normal” “and there is
nothing to be done about it” and when I check g_gravity
in the console it is 800.

So, it seems you can query them but not change them.

Oh well.

SiliconSlick


(T34R4k) #16

Is there a scripting reference manual containing all keyword, syntax descriptions …?
What means LDR ?
Is it possible to assign a accums value to another accum ?
Is it possible to equal a accums value to another accum ?

thx 4 help :slight_smile: Thomas


(The Wanderer) #17

check this thread out…look for Machine for to kill’s post.
So far it’s the best explanation of accum i’ve seen.
http://www.splashdamage.com/forums/viewtopic.php?t=5677&postdays=0&postorder=asc&start=30

oh and by the way… LDR stands for Level Designers Reference or simply the ET manual that comes with radiant


(SiliconSlick) #18

Kinda… not everything but most things.

http://www.planetquake.com/simland/ldr1_1/

Not directly but I wouldn’t rule it out as being possible.

SiliconSlick (who thinks the former could be done with 1 extra accum and doesn’t feel like thinking too hard about the latter)


(T34R4k) #19

So do you know some “indirect way” to equal/assign accums with each other ?


(SiliconSlick) #20

[quote=“T34R4k”]

So do you know some “indirect way” to equal/assign accums with each other ?[/quote]

I think the following might work for assignment:


// Transfer globalaccum 1 to globalaccum 2 using globalaccum3 as a temp
// ASSUMPTION:  globalaccum 1 is positive (could be adapted to handle the negative case)
//              and isn't much larger than zero (could get nasty with large values)
foo{

	trigger xfer {
		globalaccum 3 set 0
		trigger foo countdown
		trigger foo countup
	}

	trigger countdown { 
		globalaccum 1 abort_if_equal 0
		globalaccum 1 inc -1
		globalaccum 3 inc 1
		trigger foo countdown
	}

	trigger countup {
		globalaccum 3 abort_if_equal 0
		globalaccum 3 inc -1
		globalaccum 1 inc 1
		globalaccum 2 inc 1
		trigger foo countup
	}
}

but I haven’t actually tested it.

SiliconSlick