Scripts / [SOLVED] Setting Global Variables as Entity Indexes

Author
Message
Teabone
Forum Support
17
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 11th Jul 2018 05:12
Hey all I have an incredibly basic LUA question here. Why does Game Guru crash when I attempt to set a variable as the entity's index number?

crashes when I use either
entityindexvariable = e
entityindexvariable = g_Entity[e]

I'm just trying to make a write a global variable as the entities index so that I can do a variety of things with other entities knowing another entities index number. For instance the ability to Hide or Show other entities (without knowing their index number predetermined but simply by using global variables that were assigned the index numbers. Unfortunate GG crashes when i attempt to set these variables.
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960

The author of this post has marked a post as an answer.

Go to answer
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Jul 2018 08:43
Maybe those globals are already used elsewhere and you are corrupting them? Without seeing the script or seeing any error message you may be getting I can't really do more than guess.

Best advice is don't use global variables without appending the name of the script to them and the g_ bit in front, that way you can be pretty sure they are unique.

Been there, done that, got all the T-Shirts!
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 11th Jul 2018 09:07
This post has been marked by the post author as the answer.
Where are you calling that? To return 'e' you will need to be inside one of the related functions - I.e. init(e), main(e), exit(e) - as the (e) means the 'e' number is being passed to the functions, if you are trying to define the variable above the functions in the script it won't know what 'e' is
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Teabone
Forum Support
17
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 11th Jul 2018 18:06 Edited at: 13th Jul 2018 16:05
Thanks guys, its been a while since i jumped back into LUA. I was trying to call the value from outside of the functions, so basically just receiving a nil value. That could explain the issues. Will do another test when I get home.

EDIT: everything works fine, noob error had everything before the functions
Twitter - Teabone3 | Youtube - Teabone3 | Twitch - Teabone3 | TGC Assets - Store Link | Patreon - Teabone3

i7 -2600 CPU @ 3.40GHz - Windows 7 - 8GB RAM - Nivida GeForce GTX 960

Login to post a reply

Server time is: 2024-04-18 23:37:54
Your offset time is: 2024-04-18 23:37:54