Page 2 of 3

Re: Beta-1.2.9 now available!

Posted: Fri Sep 21, 2012 7:12 pm
by cromcrom
Can a string be stored as a variable in that way ?

Re: Beta-1.2.9 now available!

Posted: Fri Sep 21, 2012 7:17 pm
by Montis
Sure, you would just need to enclose it in quotation marks.

Re: Beta-1.2.9 now available!

Posted: Fri Sep 21, 2012 8:26 pm
by cromcrom
That's weird, it returns a nil value. I must be doing something wrong...

Re: Beta-1.2.9 now available!

Posted: Fri Sep 21, 2012 8:41 pm
by Lmaoboat
cromcrom wrote:That's weird, it returns a nil value. I must be doing something wrong...
Are you making sure to use a function? If you have it just sitting in a script, it'll try and do everything at the same time.

Re: Beta-1.2.9 now available!

Posted: Fri Sep 21, 2012 8:48 pm
by cromcrom
I am sorry, I don't get it so far :-(
1st SE :

"crom_variables"

Code: Select all

function setVar(var,number)
var = number
end

function addToVar(var,numbertoadd)
var = var + numbertoadd
end

function subFromVar(var,numbertosub)
var = var - numbertosub
end
try_1 = 0
2nd is whatever, called from a button

Code: Select all

function check()
crom_variables.setVar(try_1,1)
print(crom_variables.try_1)
end
it returns 0 while I expect 1...

Re: Beta-1.2.9 now available!

Posted: Fri Sep 21, 2012 11:20 pm
by Montis
I don't think you can substitute variables that way.

That's why it uses the try_1 value that you set.

Re: local/global "persistant" variables, in scripts, in func

Posted: Fri Sep 28, 2012 4:18 pm
by Komag
just another note on this from a problem I ran into when working on the pit puzzle:
viewtopic.php?f=14&t=3381&start=20#p34449
"global" (or "persistent") variables will be stored in save games and the datatypes that are supported in save games is limited. You cannot save tables or variables that contain game objects; they should only be used locally.
so, for example, you can have something like:

Code: Select all

namepart = "pitpuz"
which will persist across saves, and any other functions that call for namepart will replace it with "pitpuz"
but you cannot actually refer to any placed items, such as:

Code: Select all

thelever = pitpuzlever1
unless you put it inside a function and put "local " in front of it, so it will just be local to that function

Re: Beta-1.2.9 now available!

Posted: Wed Feb 27, 2013 2:33 am
by hades200082
@cromcrom try this ....

"crom_variables" - this looks fine

2nd is whatever, called from a button - try the following

Code: Select all

function check()
crom_variables.setVar(crom_variables.try_1,1)
print(crom_variables.try_1)
end
Let me know if it works for you :)

Re: local/global "persistant" variables, in scripts/function

Posted: Wed Feb 27, 2013 5:15 am
by Komag
are you just kidding? This was five months ago (maybe you didn't notice the dates). I haven't seen him in a while.

Re: local/global "persistant" variables, in scripts/function

Posted: Wed Feb 27, 2013 5:44 am
by Neikun
I remember Crom was always disappointed in a lack of feedback.
How did you even find this thread, Hades? lol