• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Global Variable does not exist

jestem pro

That is the question
Joined
Apr 20, 2013
Messages
650
Solutions
14
Reaction score
87
Hello, I noticed that I cannot use global variable.

For example:
in action I have a script with CHEST = 1740.

I wanna use it in globalevent but it gets an error. When I move it in to the original script it works.

TFS 0.3.6

Before probably it worked.
 
Solution
X
Hello, I noticed that I cannot use global variable.

For example:
in action I have a script with CHEST = 1740.

I wanna use it in globalevent but it gets an error. When I move it in to the original script it works.

TFS 0.3.6

Before probably it worked.
If you wish for it to be a global variable put it into data/lib/000-constant.lua
LUA:
CHEST = 1740
Hello, I noticed that I cannot use global variable.

For example:
in action I have a script with CHEST = 1740.

I wanna use it in globalevent but it gets an error. When I move it in to the original script it works.

TFS 0.3.6

Before probably it worked.
If you wish for it to be a global variable put it into data/lib/000-constant.lua
LUA:
CHEST = 1740
 
Solution
oh yeah it works, but can you answer on my 2 questions:

1. in this thread global variables are used not in this way you told

2. Can you tell me why this does not work:
LUA:
local chest = doCreateItem(CHEST, 1, {x=1000, y=1000, z=7})
                    doItemSetAttribute(chest.uid, "actionid", 19000)

gives the error:
"attempt to index local 'chest' (a number value)"

it's stupid but I can't
 
oh yeah it works, but can you answer on my 2 questions:

1. in this thread global variables are used not in this way you told

2. Can you tell me why this does not work:
LUA:
local chest = doCreateItem(CHEST, 1, {x=1000, y=1000, z=7})
                    doItemSetAttribute(chest.uid, "actionid", 19000)

gives the error:
"attempt to index local 'chest' (a number value)"

it's stupid but I can't
This is for TFS 1.X and not 0.X. Upgrade your stuff already...
 
oh yeah it works, but can you answer on my 2 questions:

1. in this thread global variables are used not in this way you told

2. Can you tell me why this does not work:
LUA:
local chest = doCreateItem(CHEST, 1, {x=1000, y=1000, z=7})
                    doItemSetAttribute(chest.uid, "actionid", 19000)

gives the error:
"attempt to index local 'chest' (a number value)"

it's stupid but I can't
(1) 1.x+ 's lua system is more open.
in 0.3.6 actions/creaturescripts/globalevents - et cetera are closed and can only see stuff inside that folder. (with the exception of stuff inside lib)

2) If you've set your global variable as Chest / CHEST, and then modify that variable to hold new data, such as in this example, it will no longer be the same data.. because you've now assigned it something else.

If you intend in using it this way, I'd suggested modifying the global variable to be
ITEM_CHEST = 1740

This way it's more clear, and you won't accidentally re-write it with a local variable.

stop using 0.x functions in 1.x scripts
He's using 0.3.6
This is for TFS 1.X and not 0.X. Upgrade your stuff already...
There's no reason to bully him into upgrading.
 
thanks all of you, but I intend upgrade my stuff to 1.X coz I have my own sources with a lot of changes.

@Xikini the global variable is not related to that issue. I cannot set actionid when the chest is creating.
It's something strange, coz in others scripts there is similarly and works
 
thanks all of you, but I intend upgrade my stuff to 1.X coz I have my own sources with a lot of changes.

@Xikini the global variable is not related to that issue. I cannot set actionid when the chest is creating.
It's something strange, coz in others scripts there is similarly and works
Oh.
remove .uid on the line that's setting the aid.
chest.uid -> chest
 
Back
Top