ID:270406
 
can you make one varuabke my putting two variables together?
var/b=1
var/a=2
var/c=a+b
Uhhh...do you mean like

var
a
b
c

c = a + b

?
In response to Pyro_dragons
yes
In response to Mysame
when i do that i get this error

vars.dm:16:error:obj_str:undefined var
vars.dm:16:error:base_str:invalid variable
vars.dm:16:error:= :expected a constant expression
In response to Scissors Man
For that we'd nee to see coooddeee..
In response to Mysame

mob
var
total_str=obj_str+str
In response to Scissors Man
You didn't get those errors from that code.

Here's what you need to know:
Variables need to be defined within the lexical scope of where they will be used. Let me demonstrate briefly what I mean:

var/aardvark = 5
mob/verb/baloon()
var/catharsis = 8
world << aardvark // this works, because aardvark has
// a universal lexical scope. Since
// you defined it at the "root" of
// your code, it will always be in
// the lexical scope

world << catharsis// this also works, because catharsis
// is defined within this procedure.
// that places it inside this
// procedure's lexical scope.
mob/verb/dinghy()
world << catharsis// this will NOT work, because
// catharsis is outside of this verb's
// lexical scope. Because it is
// defined only in the baloon() verb,
// it is meaningless here.
// Thus, this part of the code will
// create a runtime error. Yikes!
mob/verb/eskimo()
if(key == "PirateHead")
var/fence = "gallop"
// here, we have a special scope
// being defined inside this procedure.
// at this point, we can use fence
// like this:
world << fence
world << fence // This line will not compile and will
// give an error, because we have now
// left the lexical scope of the fence
// variable.
mob/verb/haiku()
var/ice = 1
if(ice==1) // here, we nest a number of lexical
var/jam = 5 // scopes within one antother.
if(jam==5) // at the end, the variables from
var/krill = 13// all of them are accessable, like so:
if(krill==13)
world << ice + jam + krill
world << ice + jam + krill
// here, however, only ice is defined.
// jam and krill are only applicable
// inside their respective scopes.


If you knew that already, it's good. If you learned anything, I'm glad! The lexical scope of variables was confusing to me as a new programmer, and it confuses a lot of newbies as they write their code.
In response to PirateHead
ty every1