Scripts / SwitchScript Command

Author
Message
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 19th Apr 2017 00:12
Under
LUA Commands - SCRIPTS

there is this command
SwitchScript(e,str)

Switch the entities script to script named (str)

Like all the others for this command, there is no other description or explanation for using it.

Does the new (called script) script need an _init and an _main? Is the old script (calling script) still in memory and therefore are the variables both global and local still available (in use) from the old script? In the calling script do we need to use a path name from the "scriptbank" folder? If not do we need to use the extension ".lua" If we use a path name then do we need to start it off with "\"? Such as "\My Scripts\script_name.lua". However, lua uses an escape symbol "\" so I assume we will need "\\" for a single "\".

This is a good example of why we need a manual for these commands. I don't actually feel like taking the time to test all of this. I hope our lua guru's can let me know how to use the switchscript command.
When in doubt -- C4 :heh, heh, heh:

-Jamie Hyneman
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 19th Apr 2017 09:33
Use include or require command at the start of your script and then switch script inside the script.

init(e) functions are all run at level load, not sure if switch script calls it again or not so you'll have to test and see but you can simply call the init(e) function again yourself right before you switch script anyway.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 20th Apr 2017 22:56
Thank you smallg. I would never have guessed right away to use include or required functions to be able to call the SwitchScript Command.

Speaking of "Switch..." I sure do miss C's Switch/Case or VB's Select/Case. I found a way to emulate it but I probably won't go through all that work unless I use a lot of ElseIfs. Just a couple of them wouldn't really slow anything down that much I should think.
When in doubt -- C4 :heh, heh, heh:

-Jamie Hyneman
AmenMoses
GameGuru Master
8
Years of Service
Recently Online
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 20th Apr 2017 23:36
A case/switch statement is in reality just an if/elseif as far as processing is concerned so performance wise it doesn't make a lot of difference in an interpreter.

If you want to you can create a 'jump table' in Lua to mimic the way a compiled language might deal with it but it isn't really worth the effort performance wise.


Been there, done that, got all the T-Shirts!
PM
Flatlander
GameGuru Master
17
Years of Service
User Offline
Joined: 22nd Jan 2007
Location: The Flatlands
Posted: 21st Apr 2017 02:53 Edited at: 21st Apr 2017 03:48
@AmenMoses, you are so right. It's just that I was so used to using those instead of if/elseif. It's like being used to using semi-colons at the end of statements or in VB6 using endif for the end of an if statement. I can't remember if C had the if/elseif but I know that VB6 did.

Here is how one of my "_Main" functions looks in GG and it certainly doesn't need Switch/Case statements.



BTW, you see in the code above that I used the statement "Collected(e)" and used "Hide(e) to not show the entity any longer. I wonder if I should delete the entity instead; or would that delete the entity as being collected?
When in doubt -- C4 :heh, heh, heh:

-Jamie Hyneman
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 21st Apr 2017 09:37
It'll remain collected even if you delete it.
Hiding it is fine if you wanted the script to keep running but collision will remain so for some objects you will also want to switch collision off too (though I doubt a piece of paper would need collision in this case), if you're finished with the object then destroying it is generally better.
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
Recently Online
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 21st Apr 2017 09:39
I tend to just hide entities (and do CollisonOff(e) so the player doesn't trip over invisible entities ) that way I can re-use the same entity later on.

I'm not entirely sure what Destroy(e) actually does tbh!

Been there, done that, got all the T-Shirts!
PM

Login to post a reply

Server time is: 2024-03-28 19:21:41
Your offset time is: 2024-03-28 19:21:41