SRB2 Message Board

SRB2 Message Board (https://mb.srb2.org/index.php)
-   Editing Help (https://mb.srb2.org/forumdisplay.php?f=64)
-   -   Retrieving Level Header Lua? (https://mb.srb2.org/showthread.php?t=40366)

Zwip-Zwap Zapony 03-21-2015 05:58 PM

Retrieving Level Header Lua?
 
I would like to use some Lua for something in some levels I plan on making, but not others. Obviously, I'd insert "Lua.SecretStuff = 1" in the Level Header of those, and then check if mapheaderinfo[gamemap].secretstuff is equal to 1. But that's where the problem is...

If I make a Lua hook doing nothing but "print(mapheaderinfo[gamemap].secretstuff", the console is spammed with 1 when in the level, and I assume the hook would be removed if I tried to play a level without Lua.SecretStuff set. But if I check "if mapheaderinfo[gamemap].secretstuff==1"... nothing ever happens, even if the following is just "print("It works!")". The console doesn't say it removed the hook, so I don't think it thinks I did anything wrong...

Can someone please give me a working example (both the Lua and Level Header) of an if check for Level Header Lua stuff? I have tried searching the message boards before posting this, but I didn't really find anything.

fickleheart 03-21-2015 06:16 PM

The additional parameters are always saved as strings, so try using tonumber(mapheaderinfo[gamemap].secretstuff) instead. (Or if you want to be able to evaluate built-in constants, EvalMath(mapheaderinfo[gamemap].secretstuff), but that one can throw errors so you should be careful with it.) The custom parameters might also fall into a similar problem as the rest of the level header parameters of padding the string out with \0s to a fixed length, so you might need to check for that.

Zwip-Zwap Zapony 03-21-2015 06:28 PM

Quote:

Originally Posted by RedEnchilada (Post 766707)
The additional parameters are always saved as strings, so try using tonumber(mapheaderinfo[gamemap].secretstuff) instead. (Or if you want to be able to evaluate built-in constants, EvalMath(mapheaderinfo[gamemap].secretstuff), but that one can throw errors so you should be careful with it.)

I think I did try tonumber(thing), but I'm not sure. (Maybe I just remember tostring-ifying it or something for the print check thing.) I guess I'll try that again, then.

Quote:

Originally Posted by RedEnchilada (Post 766707)
The custom parameters might also fall into a similar problem as the rest of the level header parameters of padding the string out with \0s to a fixed length, so you might need to check for that.




Edit: Okay, tonumber-ing it seems to work... even though I could've sworn I had tried that before. Thank you.

carlrev 05-26-2020 03:16 AM

Can you make an example of a lua string to not execute a command in a specific map?

Zwip-Zwap Zapony 05-26-2020 12:32 PM

Quote:

Originally Posted by carlrev (Post 824212)
Can you make an example of a lua string to not execute a command in a specific map?

Yes... but fickleheart already helped me solve this more than 5 years ago.


All times are GMT. The time now is 11:02 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.