SA-MP Forums Archive
Wondering about something, just out of curiosity. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Wondering about something, just out of curiosity. (/showthread.php?tid=177370)



Wondering about something, just out of curiosity. - Hiddos - 17.09.2010

So I figured out it was possible to insert "defined" values into string parameters like this:

pawn Code:
#define cowstring "Cows are over "
#define cowamount 9000

print(#cowstring #cowamount "!!!!!");
Note that this'll print "Cows are over 9000!!!!!".

Now my burning question is: Is it possible to use exactly the same method, but then with simple variables?"


Re: Wondering about something, just out of curiosity. - Hiddos - 18.09.2010

That's a bump hehe, guess it's allowed now.

I also wondered about something different: When should I use "new" variables and when should I use "static" ones?

I already had this timer idea:

pawn Code:
new timertimer;
public OnRoundStart()
{
  timertimer = SetTimer("Timer", 1000, 1);
}

forward Timer();
public Timer()
{
  static seconds, minutes = 10;
  if(seconds == 0 && minutes == 0)
  {
    OnRoundEnd();
    minutes = 10;
    KillTimer(timertimer);
    return;
  }
  if(seconds == 0) { seconds = 60; minutes--; }
  seconds--;
  new string[6];
  if(seconds < 10) format(string, sizeof string, "%d:0%d", minutes, seconds);
  else format(string, sizeof string, "%d:%d", minutes, seconds);
  TextDrawSetString(TimerTXT, string);
}
But now I'm just wondering if this is correct usage for it or not ^^


Re: Wondering about something, just out of curiosity. - Kyosaur - 18.09.2010

Quote:
Originally Posted by Hiddos
View Post
That's a bump hehe, guess it's allowed now.

I also wondered about something different: When should I use "new" variables and when should I use "static" ones?

I already had this timer idea:

pawn Code:
//stuff
But now I'm just wondering if this is correct usage for it or not ^^
Well it really depends on what your variable stores. The difference between "new" and "static" is that static retains its value when used in a function. When the function ends, the variables value is still existent. So if you have:

Code:
static test = 5;
test++;
in a function, and you call that function 3 times, your results will be 8 instead of it being 6.


EDIT:

Oh yeah, when you assign a value to the static variable while initializing it, that assignment only happens that one time :P.


As for your first post: No. The stringize operator is very literal, if you do something like #var it will add "var" into the string, instead of the value.


Re: Wondering about something, just out of curiosity. - Hiddos - 18.09.2010

Quote:
Originally Posted by Kyosaur
View Post
Well it really depends on what your variable stores. The difference between "new" and "static" is that static retains its value when used in a function. When the function ends, the variables value is still existent. So if you have:

Code:
static test = 5;
test++;
in a function, and you call that function 3 times, your results will be 8 instead of it being 6.
Ah thanks for explaining, now I fully got that part ^^. But any idea about the macro/define question?


Re: Wondering about something, just out of curiosity. - Kyosaur - 18.09.2010

Quote:
Originally Posted by Hiddos
View Post
Ah thanks for explaining, now I fully got that part ^^. But any idea about the macro/define question?
Yeah i edited my post with an answer for that as well :P.