Habu_69 Posted February 3, 2013 Posted February 3, 2013 I am trying to fly a downloaded mission, but the attached LUA script returns an error: String" [--Change the values in the 2 variables low..."]attempt to index global 'os' (nil value) I do not know exactly what this script does in the mission; but I assume the problem lies with the os function in line 17, but I have no knowledge of how to fix it. Anyone wish to help with this?
Puddlemonkey Posted February 3, 2013 Posted February 3, 2013 by default, scripts can't access the OS. You can desanitize the lua environment by commenting out lines of some DCS lua files but it isn't recommended that you do it, unless it is for your own testing. What is this supposed to achieve? Maybe you can do it another way? Maybe if you post the mission, someone will sort it for you :-)
Habu_69 Posted February 3, 2013 Author Posted February 3, 2013 Thanks. A token infantryman has this script in the trigger actions. Perhaps this script is intended to randomly activate groups based on OS time. Mission attached. It is one of those interesting missions that was probably broken by subsequent updates. Those updates may have rendered the script obsolete, as well.
Grimes Posted February 3, 2013 Posted February 3, 2013 Randomseed is not accessibly within the scripting environment, however it is not needed! math.random() is replaced by the simulations own randomization scripting, so a randomseed is not required to make it truly random. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Habu_69 Posted February 3, 2013 Author Posted February 3, 2013 As I suspected. Thanks for the help. If I feel motivated, I may try to duplicate the intentions of the LUA script with the functions available in DCSW.
Puddlemonkey Posted February 4, 2013 Posted February 4, 2013 Grimes, I''m curious what the simulation's own randomisation scripting is? I have been using random flag values to set the math.randomseed. Are you saying that the DCS lua environment already randomises it and nothing is necessary? Thanks
Grimes Posted February 4, 2013 Posted February 4, 2013 My understanding is that each time the sim loads it is supposed to use a new random seed. In the DCS.log there should be an entry for that, something like: 00008.325 INFO DCS: Dispatcher: initial random seed = 3531977 I mean't to say in my first post that the OS library is not available, randomseed is available and you should be able to use it, but its not needed. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Druid_ Posted February 4, 2013 Posted February 4, 2013 (edited) That script is a randomisation script I wrote quite some time ago in an earlier version of DCS when we had access to OS functions. OS functions were taken out of the scripting environment due to obvious security reasons If you delete the line math.randomseed( OS.time() ) it should work fine. It may be worth mentioning that the seeded value is also saved to the .trk file so that the mission plays back correctly. The simulator scripting environment is passed a random seed. As to the code for that seed, it is done within the secure DCS environment and it's content is known only to the Dev. I suspect however that it uses the OS time to create. Edited February 4, 2013 by Druid_ i7-7700K : 16Gb DDR4 2800 Mhz : Asus Mobo : 2TB HDD : Intel 520 SSD 240gb : RTX 2080ti: Win10 64pro : Dx10 : TrackiR4 : TM Warthog : ASUS ROG SWIFT PG348Q
Puddlemonkey Posted February 4, 2013 Posted February 4, 2013 Cheers guys, that has saved me some hassle :-)
Habu_69 Posted February 4, 2013 Author Posted February 4, 2013 Interesting discussion. After further review, it appears that script was intended only to randomize the activation of 5 sets of SHORAD (or am I wrong?). Much more direct to simply do that within the available trigger functions now. I am using the fixing of these old, but nicely designed, missions as a vehicle to learn the ME functions. I really should post them to ED as they are updated.
Bahger Posted April 13, 2013 Posted April 13, 2013 I'm pleased that my mission is deemed worth the effort of fixing scripting elements broken by changes in the way the engine handles randomization. I did indeed consult with Druid -- and, of course, Grimes -- in getting a simple randomization routine to work and, yes, all it does is vary the placement of defensive units by selecting amongst five possible arrangements. Various people have taken it upon themselves to fix my missions post-DCSW, and, as I said, I'm flattered and grateful. Going forward, can anyone guide me re. how to accomplish the kind of randomization I was able to achieve -- via having my hand held by Druid and Grimes because I am a moron with scripting -- in the ME? If all I want to do is get the engine to choose one out of five arrangements of defenses, how would I do this in the ME?
Grimes Posted April 13, 2013 Posted April 13, 2013 With triggers: Once> Random x% and Flag 1 is False> Set Flag 1 and Activate Group 1 Once> Random x% and Flag 1 is False> Set Flag 1 and Activate Group 2 etc. Scripting isn't entirely needed for this sort of thing because you are still activating the group via triggers anyways. But you can do it simply with something like this: trigger.action.setUserFlag(tostring(math.random(5)), true) Which will randomly set flag 1-5 true. The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Recommended Posts