Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Epyo

Putting an int in an action

Recommended Posts

script 802 OPEN
{
	int sector;
	sector++;
	Ceiling_LowerInstant(i: sector,s: 0, 304);
	delay(10);
	restart;
}
If you can't figure out what I'm trying to do, it's supposed to lower the ceiling of sector tag 1, then 2, then 3, then 4, and so on and so on. But I can't really figure out how to put the "sector" into the action. I know how to do it with hudmessages, but it doesn't seem to work the same with this.

Share this post


Link to post

I don't think it works that way. I guess your "sector" variable gets reset each time the script restarts. Use a loop like this:

script 802 OPEN
{
     int sector;

     for(sector=0; sector < 10; sector++) {
          Ceiling_LowerInstant(sector, 0, 304);
          delay(10);
     }     
}
Of course you have to set the right values in the loop's head.

Share this post


Link to post

oh so I don't even need the i: and the s: thingys huh, ok that helps thanks.

Share this post


Link to post

They are not required, but maybe it works with them, I don't know. They are required with print and hudmessage though, IIRC.

Share this post


Link to post

OMG!

script 802 OPEN
{
     for(int sector=0; sector < 10; sector++) {
          Ceiling_LowerInstant(sector, 0, 304);
          delay(10);
     }     
}
not that it matters, and yes boris is right, if you restart a script then the variable (sector) will get reinitialized every time to zero. You could, however, do this:
script 802 OPEN
{
	int sector;
zuh:	sector++;
	Ceiling_LowerInstant(sector, 0, 304);
	delay(10);
	goto zuh;
}
if you really wanted to, but then that will never terminate and in fact it'll probably overflow after a while and restart raising at sector 0 again (will take days tho I think)

Share this post


Link to post
boris said:

Every time you use goto god kills a kitten. Please, think of the kittens!




Same old lame statement as ever. Why doesn't it die?

Share this post


Link to post

Umm actually no the variable isn't resetting to zero each time, and I still have my original script but without the s: and i: thingys. Weirdos!

EDIT: Ok now in a totally different script I'm trying to use the goto thing but it says that my feh: is an invalid argument;

script 777 (void)
{
	int sectora;
	sectora = 251;		
feh:		sectora--;	
		Sector_SetDamage(sectora, 0, 14);
		changefloor(sectora, "GRASS2");
		delay(1);
		Goto feh;
}

Share this post


Link to post

I usually declare variables above the script, and outside. Meh, it works.
[B]

int sectora;
sectora = 251;	
script 777 (void)
{
        sectora--;	
	Sector_SetDamage(sectora, 0, 14);
	changefloor(sectora, "GRASS2");
	delay(1);
	restart;	
}
But really this should be in a for loop, or at least have a
if(sectora < lowest_sector_tag_number){terminate;}
between sectora--; and sector_setdamage.

Share this post


Link to post
Bloodshedder said:

I suppose ACS doesn't support initializing a variable as static.


Of course it does. Outside a script write

int variable=1337;


Just like in C!

Share this post


Link to post
Bloodshedder said:

Eh, yes I know that will work, I meant with the static keyword. Local scope but global persistence.




Use a global variable that's only referenced to in one ACS file and you'll have exactly that.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×