local/global "persistant" variables, in scripts/functions

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Beta-1.2.9 now available!

Post by cromcrom »

Can a string be stored as a variable in that way ?
A trip of a thousand leagues starts with a step.
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: Beta-1.2.9 now available!

Post by Montis »

Sure, you would just need to enclose it in quotation marks.
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Beta-1.2.9 now available!

Post by cromcrom »

That's weird, it returns a nil value. I must be doing something wrong...
A trip of a thousand leagues starts with a step.
Lmaoboat
Posts: 359
Joined: Wed Apr 11, 2012 8:55 pm

Re: Beta-1.2.9 now available!

Post 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.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Beta-1.2.9 now available!

Post 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...
A trip of a thousand leagues starts with a step.
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: Beta-1.2.9 now available!

Post by Montis »

I don't think you can substitute variables that way.

That's why it uses the try_1 value that you set.
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

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

Post 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
Finished Dungeons - complete mods to play
hades200082
Posts: 14
Joined: Sun Feb 24, 2013 5:49 pm

Re: Beta-1.2.9 now available!

Post 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 :)
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

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

Post 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.
Finished Dungeons - complete mods to play
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

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

Post by Neikun »

I remember Crom was always disappointed in a lack of feedback.
How did you even find this thread, Hades? lol
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
Post Reply