Scripts / enter data: while loop trouble...

Author
Message
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 5th Aug 2019 22:23
I put this at the beginning of a (always running) script,
when first going into test mode, GG locks up and does not
enter the map-- stays at the keyboard controls screen.
What did I do wrong?

I also hit some number keys while it was locked because it is
supposed to wait until a number from 1-9 is entered...

while entlev[e] < 2 or entlev[e] > 9 do --- scan codes for 1-8
TextCenterOnX(50,15,3,"Enter Beginning Level 1-8: ")
entlev[e] = g_Scancode
end
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

>>>>> before this runs (init)-
entlev[e] is assigned local {}
and entlev[e] = 0
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 6th Aug 2019 09:37
scancode won't ever change because it doesn't exit the script to get back to the global.lua to find out what to do with scancode.
i guess this is on a blank map?
take out the while loop and use a variable instead


if you're not on a blank map you will want to factor in a way to stop the player / AI from doing stuff you don't want it to do until the level is chosen (FreezeAI , TransportToFreezePosition / lock player in a room etc)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 6th Aug 2019 20:26
One of the concepts that seems to be hard for people to grasp is that of scripts executing once per frame.

All the state variables like key presses and g_Entity values are set for the frame prior to your script being called and cannot be updated until the next frame so you cannot wait for them to change in a while loop (for example).

Scripts do not run in parallel either, so if you have ten entities all with the same script attached then the script will be called for entity 1 then when the script exits it will be called again for entity 2 etc.

The upshot of this is that any changes made to global state variables by the call for entity 1 will be seen by the call for entity 2, this is why you need to have variable lists keyed by entity number (or use the concept of a control entity so only one calling entity controls the state variables).

In an age of object oriented teaching this should really be intuitive as you should think of each script as being a separate object.

Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 11th Aug 2019 22:36
Radical guys. Great info again.
This environment right here is my first classroom for object oriented scripts...
One slow bit at a time!
PM

Login to post a reply

Server time is: 2024-03-29 14:01:44
Your offset time is: 2024-03-29 14:01:44