Scripts / Weak or broken Global variables...?

Author
Message
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 13th Jun 2020 18:15 Edited at: 13th Jun 2020 18:29
Hey guys. So often I want to make a script where I determine the location of
entities from a different script, and then move that entity (called from a
separate entity script). Quite a bit frustrating at times, because it seems like
you have to Strong-Arm the global variables into being recognized by GG,
and sometimes not any luck with trying to do it. Usually you can rely on the
Global.lua variables working (if the engine accepts the change)

I tried to assign my own globals, it doesn't recognize them, and so I tried to use
Global.lua entity variables-- which even broke GG. Why did this return a Runtime
Error- and shut down? ;;;

g_Entity[e-1]['x'] = g_Entity[e-1]['x'] + plrsdistx[e]
g_Entity[e-1]['z'] = g_Entity[e-1]['z'] + plrsdistz[e]

for sure the entity number exists. e[5] is calling to move e[4] // e-1
but it shut down GG......???

Anybody know what // UpdateEntitySMALL // function does?
UpdateEntitySMALL(e,object,x,y,z)
g_Entity[e] = {x=x; y=y; z=z; obj=object;}
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Jun 2020 18:21
You can't set the g_Entity list values from a script!

g_Entity values are for the engine to communicate them to the Lua script. i.e. it is filled in from the internal engine values each frame.

To move an entity you need to use one of the many functions available, e.g. PositionObject( objId, x, y, z ) is one of them.
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 13th Jun 2020 18:37
Okay. I'll try that one, but I was using...
SetPosition(g_Entity[e-1]['x'], g_Entity[e-1]['y'], g_Entity[e-1]['z'])--- set object down

Oooops... now I see my mistake. 'e' is actually absent. I do try to verify my probs
a few times before posting here!! But my original complaint about elusive globals
that are finicky about being recognized is still a thing?! - ? I guess it's just me.
I look like this at the screen...
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 13th Jun 2020 18:40 Edited at: 13th Jun 2020 18:51
For example these are globals, and certainly active variables;;
ex[e-1] = ex[e-1] + plrsdistx[e]
ez[e-1] = ez[e-1] + plrsdistz[e]
SetPosition(e-1, ex[e-1], ey[e-1], ez[e-1])--- set object down

but they get error out nil.... BTW above is what I originally had in the first place.
Any thoughts?
PM
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 13th Jun 2020 18:41
Quote: "Anybody know what // UpdateEntitySMALL // function does?
UpdateEntitySMALL(e,object,x,y,z)"


-- Common Updater Functions (called by Engine)

Some Lua commands should exist on global.lua file, although they are used only by engine internal code.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 13th Jun 2020 18:46
You are trying to play with funky maths with entity ids, currently, you are able to get entity ids via a script, even with ames obj convert to id.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 13th Jun 2020 18:55
Nice. It's working. Maybe I did miss a letter or number here or there, but
well it seems like I have to fight with globals sometimes rigorously in order
for them to get active. And other times they are a little more cooperative.

Thanks for your kind help. I'll probably have issues again in the future, and
I'll battle with them again until they surrender!!
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 13th Jun 2020 20:35
To simplify your code do this:

local Ent = g_Entity[ e ]

Then you can access all the variables with:
Ent.x
Ent.z
Ent.angley

etc

Make your code much easier to read imo.

Alternatively use the advanced functions:

local x, y, z, xA, yA, zA = GetObjectPosAng( objId )

That way you get all positional and angular values with one command ( but notice it uses object Id not e ).

If you only want some of the values simply replace the ones you don't want with '_':

local x, _, z, _ yA = GetObjectPosAng( objId ) fo example.
Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-12-22 03:31:48
Your offset time is: 2024-12-22 03:31:48