Jump to content
  • 0

Math is hard guys -- ACS integer trouble


Wo0p

Question

Hey forums :) Another coding issue on my end.

 

In a Map Script:

	int x = 0;
	int y = 0;
	Delay(1);
		y++;
		x = (y*25) + 100;

 

Provides "125" as it ought to. But the trouble is, this script can be called several times and if it is, it always displays 125 (through a hudmsg script):

 

HudMessage(s:"\cbYour \cdRun Speed \cbis now \cg", d:x, s:"\cb% (Saved to console log)"; HUDMSG_TYPEON|HUDMSG_LOG, 69, CR_RED, 320.4, 80.1, 2.0, 0.005, 1.0);

 

So being the inept coder that I am, could someone point out what I'm doing wrong?

Share this post


Link to post

4 answers to this question

Recommended Posts

  • 3

If that first part is not inside of a loop, but you're calling the script multiple times, then the value of y keeps on resetting.

To solve this you can just define the integer outside of the script instead.

int y;
script "DoStuff" (void) {
	y++;
	int x = y*25 + 100;
	
	etc...

 

Share this post


Link to post
  • 1
26 minutes ago, Wo0p said:

 

Thank you so much! Works like a charm :)

 

Though an additional question if I may. Since the integer is now outside the script, it will be affected by several different players if they each activate the script. Will I have to delve into cvars and ACS scripts from my pk3 to solve this? I know the scope of this question just ballooned out of proportions but if you have an inkling of which direction I should go, it would be highly appreciated.

 

No obligations, of course. Just in case you happen to know the answer. :)

 

A bit of a darker realm you're delving here x)

 

Anyhow, there's no need of cvars, you only need global arrays and player numbers

 

I believe something like this should work:

global int 0: yvar[]; //our global array that you will be able to access from every map (you should be able to set it up in any map script, without having to make a ACS lump in your pk3)

script "DoStuff" (void) { //it lets every single player to have its own variable that it will be stored in the global array and will be accessed depending on the player who activates the script based on his number, which differs from player to player
	yvar[PlayerNumber()]++;
	int x = yvar[PlayerNumber()]*25 + 100;

	etc..

I don't think you'll need anything else actually, but maybe you'll need to first define a value for the array variables with something like this:

script "VarSetup" ENTER {
	yvar[PlayerNumber()] = 0;
}

 

Share this post


Link to post
  • 0
14 minutes ago, Kan3 said:

If that first part is not inside of a loop, but you're calling the script multiple times, then the value of y keeps on resetting.

To solve this you can just define the integer outside of the script instead.


int y;
script "DoStuff" (void) {
	y++;
	int x = y*25 + 100;
	
	etc...

 

 

Thank you so much! Works like a charm :)

 

Though an additional question if I may. Since the integer is now outside the script, it will be affected by several different players if they each activate the script. Will I have to delve into cvars and ACS scripts from my pk3 to solve this? I know the scope of this question just ballooned out of proportions but if you have an inkling of which direction I should go, it would be highly appreciated.

 

No obligations, of course. Just in case you happen to know the answer. :)

Share this post


Link to post
  • 0
51 minutes ago, Kan3 said:

 

A bit of a darker realm you're delving here x)

 

Anyhow, there's no need of cvars, you only need global arrays and player numbers

 

I believe something like this should work:


global int 0: yvar[]; //our global array that you will be able to access from every map (you should be able to set it up in any map script, without having to make a ACS lump in your pk3)

script "DoStuff" (void) { //it lets every single player to have its own variable that it will be stored in the global array and will be accessed depending on the player who activates the script based on his number, which differs from player to player
	yvar[PlayerNumber()]++;
	int x = yvar[PlayerNumber()]*25 + 100;

	etc..

I don't think you'll need anything else actually, but maybe you'll need to first define a value for the array variables with something like this:


script "VarSetup" ENTER {
	yvar[PlayerNumber()] = 0;
}

 

 

Haha yeah I know... it's a dark and scary realm... x)

Ooooh arrays. Never used those before so yeah you're right I might have to explore those options. Thanks for the suggestion and the example, much appreciated! I'll keep tinkering. :)

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...