4 arguments,reusable script for intrmittently pushable walls

Discuss all aspects of editing for ZDoom.
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

4 arguments,reusable script for intrmittently pushable walls

Postby cocka » Mon Jun 25, 2012 3:36 pm

Hello!

Is there a way to give a script special more than 3 arguments? I'd like to have four, but there is no field for the fourth one.

Here is the script:

Code: Select allExpand view
int tolasok[100];
script 1 OPEN
{
    for(int x = 0; x < 100; x++)
    {
    tolasok[x] =  1;
    }
}

script 2 (int polyid, int ttav, int tav)
{
    if(tolasok[polyid-1] <= ttav/tav)
    {
    Polyobj_Move(polyid, 3, 0, tav);
    polywait(polyid);
    tolasok[polyid-1]++;
    }
}


And I would like to have something like this in script 2:

Code: Select allExpand view
script 2 (int polyid, int ttav, int tav, int irany)
{
    if(tolasok[polyid-1] <= ttav/tav)
    {
    Polyobj_Move(polyid, 3, irany, tav);
    polywait(polyid);
    tolasok[polyid-1]++;
    }
}


In this way two scripts would be enough for solving the issue, otherwise I have to use four copy of this where irany changes according to the direction. 0, 64, 128 and 192.

Does anyone have a useful tip for this issue?
Last edited by cocka on Tue Jun 26, 2012 3:12 pm, edited 1 time in total.
User avatar
cocka
 
Joined: 02 Jul 2011
Location: Hungary

Re: More than 3 arguments

Postby Isle » Mon Jun 25, 2012 6:34 pm

depending on the numbers passed you could combine the numbers into high and low bytes.
another idea is to make an array with the arguments you want then have the line pass the index of the arguments.
User avatar
Isle
WadAuthor 4 L1F3
 
Joined: 21 Nov 2003
Location: Arizona, USA

Re: More than 3 arguments

Postby Gez » Mon Jun 25, 2012 6:48 pm

cocka wrote:Is there a way to give a script special more than 3 arguments? I'd like to have four, but there is no field for the fourth one.

Actually, it is possible with an SVN build. You'll need to use ACS_ExecuteWithResult or ACS_NamedExecuteAlways to call it, though; since all other script-calling functions have room for only two or three arguments.

Also note that if you only call the many-arg'ed script from another script, you could turn use functions instead.
Gez
 
Joined: 06 Jul 2007

Re: More than 3 arguments

Postby cocka » Tue Jun 26, 2012 5:23 am

you could combine the numbers into high and low bytes.


I don't really understand how you can use high and low bytes in this case.

make an array with the arguments you want then have the line pass the index of the arguments.


OK, let's assume that we have that array. How does it look like?

Code: Select allExpand view
int array[4] = {But how do you define the elements, depending on the passed arguments?};


You'll need to use ACS_ExecuteWithResult


OK, but in this case what would be the result value?
User avatar
cocka
 
Joined: 02 Jul 2011
Location: Hungary

Re: More than 3 arguments

Postby Gez » Tue Jun 26, 2012 5:51 am

If you do not explicitly set a result value with SetResultValue, it's 0.

If all you want is to execute a script with four arguments, you do not have to care about the result value.
Gez
 
Joined: 06 Jul 2007

Re: More than 3 arguments

Postby cocka » Tue Jun 26, 2012 6:10 am

I don't really understand if this withresult special is invoked from a linedef, why the description says this: the script is always run on the current map.

Actually, there is no need to run the script always on the current map. :) Just if the player pushes a wall segment somewhere in the map. As there will be more than one wall segment on the map, I decided to use one script.
User avatar
cocka
 
Joined: 02 Jul 2011
Location: Hungary

Re: More than 3 arguments

Postby Gez » Tue Jun 26, 2012 6:15 am

Look at the description for the other ACS_Execute: you can run scripts on other maps. They'll be run next time you enter that other map. That's why there's an argument "lost" in plain old ACS_Execute:
Code: Select allExpand view
80:ACS_Execute (script, map, s_arg1, s_arg2, s_arg3)

84(Script, MAP, arg1, arg2, arg3)

ACS_ExecuteWithResult, however, can only run on the current map (since if you are waiting for a result, you want it now, you can't suspend the running script until the player visits a different map and comes back). This frees a slot in the parameter list for adding a fourth argument to the script.
Gez
 
Joined: 06 Jul 2007

Re: More than 3 arguments

Postby cocka » Tue Jun 26, 2012 7:21 am

Well, I have misunderstood the meaning of the word always. I thought that the word always refers to the fact that the script runs continuously on the actual map.

I don't even think that it means the script runs on another map, because it appeared obvious to me. (if the map parameter misses, then the script will run on the current map)

So you are absolutely right, and I didn't challenge your description.
User avatar
cocka
 
Joined: 02 Jul 2011
Location: Hungary

Re: More than 3 arguments

Postby Gez » Tue Jun 26, 2012 8:09 am

Running scripts on other maps is used a lot in Hexen. Remember messages such as "a stair has risen on the Seven Portals" or "a door has opened in the Guardian of Ice"?
Gez
 
Joined: 06 Jul 2007

Re: More than 3 arguments

Postby cocka » Tue Jun 26, 2012 8:23 am

Yes, I learned ACS scripting by examining the acs scripts of vanilla hexen. But there was no acs_executealways or withresult in those scripts. :)
User avatar
cocka
 
Joined: 02 Jul 2011
Location: Hungary

Re: More than 3 arguments

Postby Isle » Tue Jun 26, 2012 2:45 pm

for arrays it'd be
Code: Select allExpand view
args[5][3] = {{12, 45, 23}, {13, 52, 24}, {13, 21, 54}, {65, 23, 76}, {13, 63, 23}};

script 2 (int polyid, int index)
{
    if(tolasok[polyid-1] <= args[index][0]/args[index][1])
    {
    Polyobj_Move(polyid, 3, args[index][2], args[index][1]);
    polywait(polyid);
    tolasok[polyid-1]++;
    }
}
oh and the default value for executewithresult is actually 1. when used on a line it decides if the switch animates or not.
User avatar
Isle
WadAuthor 4 L1F3
 
Joined: 21 Nov 2003
Location: Arizona, USA

Re: 4 arguments,reusable script for intrmittently pushable w

Postby cocka » Tue Jun 26, 2012 4:10 pm

OK, but as I said I don't know in advance the arguments, because they're passed to the script and are not from a 2D array, which has already defined values.

I overwrote the title of the topic, because the issue is a bit more complex than it looks at first sight.

So the task is to create a reusable script for intermittently pushable walls.

I had two scripts for each pushable wall. Here are these:

First one:

Code: Select allExpand view
int mapvar0 = 1;
script 1 (void)
{
SetLineTexture(1, SIDE_FRONT, TEXTURE_MIDDLE, "-");
if(mapvar0 <= 24)
{   
   Polyobj_Move(2, 3, 0, 5);
   PolyWait(2);
   mapvar0++;
}
}


Second one:

Code: Select allExpand view
int tolas = 1;
script 12 (void)
{
   if(tolas <= 17)
   {
   Polyobj_Move(50, 2, 192, 4);
   PolyWait(50);
   tolas++;
   }
}


These worked well, but the general script for these won't work. So here is the script:

Code: Select allExpand view
int tolasok[100];
script 1 (int poly, int ttav, int tav, int irany)
{
    if(tolasok[poly-1] < ttav/tav)
    {
    Polyobj_Move(poly, 3, irany, tav);
    polywait(poly);
    tolasok[poly-1]++;
    }
}


This script is invoked by an ACS_Executewithresult special set for a line of a polyobject. The line is pushable, but you have to push it several times to get the poly to its destination. Instead of map variables I defined an array with 100 elements, because I don't know the exact number of these polys on the map. One element of this tolasok array defines the number of pushes. The initial value of these are 0, and if you push one of the walls once, the variable for the actual poly increases by 1. The reason why I used 100 elements in the array is because I cannot "distinguish" (I mean keep them separated from each other) the number of pushes for each polys and keep track of them in other way.

Now about the variables:
poly: the number of the actual poly
ttav: the overall distance where the poly can move
tav: the distance the poly can cover
irany: the direction where the poly moves to

The problem is that it seems as though the zdoom ignores the polywait or somehow the expression standing after if, returns false untimely, although the poly doesn't get to its destination.

If I write another polywait(poly); before the Polyobj_Move(poly, 3, irany, tav); then the problem remains, but the poly passes its destination point if you push it too fast.
User avatar
cocka
 
Joined: 02 Jul 2011
Location: Hungary

Re: 4 arguments,reusable script for intrmittently pushable w

Postby cocka » Tue Jun 26, 2012 4:24 pm

Isle: As you can see, the 2. and 4. arguments are map specific and they depend on the overall distance that the poly should cover and the direction.
User avatar
cocka
 
Joined: 02 Jul 2011
Location: Hungary

Re: 4 arguments,reusable script for intrmittently pushable w

Postby Isle » Tue Jun 26, 2012 6:05 pm

ok, you are going to have to use acs_executewait. ACS_Executewithresult dosen't wait for the old script to finish before running a new one. as for the array, you can just set the values in an open script on the map. you could even combine the poly array and the arg array.
Code: Select allExpand view
int tolasok[100][4];

script 1 (int poly)
{
    if(tolasok[poly][0] < tolasok[poly][1]/tolasok[poly][2])  //take out the -1 to make the index match the poly num
    {
    Polyobj_Move(poly, 3, tolasok[poly][3], tolasok[poly][2]);
    polywait(poly);
    tolasok[poly][0]++;
    }
}

script 100 OPEN
{
    tolasok[1][1] = 123;
    tolasok[1][2] = 245;
    tolasok[1][3] = 128;

    tolasok[2][1] = 98;
    tolasok[2][2] = 158;
    tolasok[2][3] = 68;

    tolasok[3][1] = 83;
    tolasok[3][2] = 166;
    tolasok[3][3] = 95;
}
User avatar
Isle
WadAuthor 4 L1F3
 
Joined: 21 Nov 2003
Location: Arizona, USA

Re: 4 arguments,reusable script for intrmittently pushable w

Postby cocka » Tue Jun 26, 2012 7:07 pm

the old script


Where is it? :oops: I substituted one general script for the two scripts. There were two, because there have been only two polys using this push effect so far.

Don't forget that the withresult special is invoked by a linedef in this case, but executewait cannot be invoked by a linedef.
User avatar
cocka
 
Joined: 02 Jul 2011
Location: Hungary

Next

Return to Editing

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest