Variable meet condition

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
Norm49
Posts: 96
Joined: Fri Jun 05, 2015 3:59 pm

Variable meet condition

Post by Norm49 »

Hi, I was trying to have a event fire after multiple trigger were meet. It think it was over complicated and I try to simplify it by having a value increase by one every time the player complete a objective. Most of my experience scripting is form Unity Bolt visual scripting. I don't know lua much.

Value name is Rescue.

I have a trigger 5 second after the scenario start. It activate a action, a lua script.
Rescue = 0

In my trigger to detect the objective completing I have multiple thing such as message. They all work fine. I also have a lua script.
Rescue = Rescue + 1

I have a trigger 10 second after the scenario start. It activate a action, a lua script. The action that should trigger is the ending of the scenario.
Rescue = 7


It doesn't work. Can any one explain to me the many ting I done wrong?
Thanks

P.S. I try to put the scenario in attachment but I revive a error message because I can send that type of file.
User avatar
blu3s
Posts: 1126
Joined: Fri Jul 08, 2022 9:45 am

Re: Variable meet condition

Post by blu3s »

You can zip the scen to upload here.

Make sure that your variable is accesible in the scen, do a print(Rescue) from the Lua Console to check the value before/after the triggers.
Norm49
Posts: 96
Joined: Fri Jun 05, 2015 3:59 pm

Re: Variable meet condition

Post by Norm49 »

Apparently I also don't understand how to use the print command.

Any ways the scenario is now in attachment.
Attachments
Senario.zip
(29.8 KiB) Downloaded 11 times
User avatar
blu3s
Posts: 1126
Joined: Fri Jul 08, 2022 9:45 am

Re: Variable meet condition

Post by blu3s »

To open the Lua Console enter scenario in editor mode, then go to

Editor->Lua Script Console


In the console you can run lua code to check that it's correct and see that it does what you want to do.

To initialize the variables, it's common and desirable to do so at the beginning of the scenario. In the case of variables that will be used throughout the scenario and that can take different values, it's necessary that these variables are saved with the scenario so when a player loads/saves his scenario these variables maintain the same value and aren't lost. To do this there are two methods that I leave you below.

https://commandlua.github.io/assets/Fun ... Value.html
https://commandlua.github.io/assets/Fun ... Value.html

So for your scenario, a first approximation would be:

Change the Set Variable event trigger to a scenario starts type trigger

Change the lua code to something like:

Code: Select all

if ScenEdit_GetKeyValue("Rescue") ~= '' then Rescue=tonumber(ScenEdit_GetKeyValue('AIRSUP_NAF')) else Rescue=0 end
Whenever you change the Rescue value you must save it with ScenEdit_SetKeyValue().


Regarding the win condition, in the conditions block, for something to meet a condition the Lua block you execute must return true. If you say Rescue=7 in the condition it will set the value to 7 but it won't do anything. It should be something like:

Code: Select all

If Rescue >= 7 then return true else return false
User avatar
lumiere
Posts: 277
Joined: Tue Mar 19, 2019 10:38 am

Re: Variable meet condition

Post by lumiere »

Nice scenario!

Event "Mission success" must be repeatable to check victory conditon by specified timing (If event conditon are not met, no action will be executed but event turns inactive like event normally fired).

As blu3s said above, it is reccomended to use keyvalue to hold values after save/loading. Make sure to use tonumber(ScenEdit_GetKeyValue("keyvalue") ) to deal value with number (not string) when calculation.

Or if you're using Lua script for event conditon, script must return boolean value true by conditional.

If you are using only one or two values for the final event condition, you can also use non-player side points as conditon value. Add 1 point to non-player side for each rescue event, then specific side points triggers the final event.
"How Do You Stay Calm With A 7,000 Ton Nuclear Predator Listening For Your Heartbeat?"
Post Reply

Return to “Lua Legion”