 |
Aekisu Novice
Joined: 08 Oct 2002 Posts: 34
|
Posted: Fri Sep 26, 2003 11:55 pm
Understanding variables |
I'm having trouble understanding variables. Maybe someone can help me out. My main problem seems to be with the use of the @ character, like when do I use it and when do I not.
Using this code seems to work correctly. 1 is added to the value in sessionkills, keeping a running total of kills I made.
#add sessionkills 1
However, when I use the following code, I get an unexpected result in TotalKills. Instead of adding sessionkills to TotalKills, TotalKills will contain the string "sessionkills". The next time the code is run, TotalKills will contain "sessionkillssessionkills".
#add TotalKills sessionkills
#math sessionkills 0
From what I understand, all variable types (text, integers, floats, etc.) are actually stored as a strings. What I don't understand is when the @ character is applied and when there is no need.
Can anyone help? |
|
|
 |
megamog75 Enchanter

Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Sat Sep 27, 2003 12:15 am |
#show @totalkills would show you the variable amount
#show %ismember(1,@totalkills) would show you if the variable had a 1 in it
#var new %item(@totalkills,1)would set the new variable as item 1 in the string list of totalkills
#math sessionkills 0
0 is fals as i understandit, if you want to make the totalkills 0 again
just do this: totalkills=0
yes strings is the way it is captured example:
#alias as {#var new %1}
would do
as never so die, would set the new variable to Never
but
#alias as {#var new "%-1"}
would do
as never say die, setting the new variable to Never say die |
|
|
 |
Aekisu Novice
Joined: 08 Oct 2002 Posts: 34
|
Posted: Sat Sep 27, 2003 2:07 am |
I got it working by using...
#add TotalRats @sessionkills
#math sessionkills 0
..but the question still remains. One time I use @sessionkills and another time, sessionkills. The use of the @ is the confusing issue.
What is a general rule I can apply to the @ ? |
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Sep 27, 2003 4:28 am |
You use @ when you want the VALUE of the variable. In this case, you want to add the VALUE (0, 11, 3, etc) of @sessionkills to TotalRats.
You leave off the @ when you want to refer to the NAME of the variable. This will usually be when you're using commands which make/alter variables and it's the variable you're changing. These are commands such as:
#VARIABLE
#ADD
#MATH
#ADDITEM
#DELKEY
#VAR varname sessionkills //Uses varname as the name and "sessionkills" as the value. @varname is now "sessionname"
#VAR @varname 15 //Uses sessionkills (the value of @varname) as the name and 15 as the value. @varname is still "sessionkills" and @sessionkills is 15
#VAR varname @sessionkills //Uses varname as the name and 15 (the value of @sessionkills) as the value. @varname is now 15, and so is @sessionkills
Hope this helped. |
|
|
 |
Aekisu Novice
Joined: 08 Oct 2002 Posts: 34
|
Posted: Sun Sep 28, 2003 4:43 am |
Thank you. That clears it up. BTW, thank you for including the comment fields. That took care of my question about comments delimiters.
|
|
|
 |
|
|