Jump to content

Ahh the joy of Mission Building and Scripting ... ...


Recommended Posts

Posted

The other day I spent at least an hour and a half chasing a bug.  I'm sure I am not alone, nor will this be the last bug to chase.  IIRC, Lua sees spaces at the end of a line as white noise.  

In the mission I am building, I am using the following line to get information associated with a certain helicopter

local Helo_Name = Group.getByName(Hot LZ Mi-24P-1)

The error message pointed to the "getByName ()" call.  Every time I tried the helo named "Hot LZ Mi-24P-1" the script would crash.  Tthe script worked fine for "Hot LZ Mi-24P-2", "Hot LZ Mi-8MTV2-1", "Hot LZ UH-1H-1" and so forth.  I tried every thing I could think of. I copied one of the working scripts over and just changed the name of the helo of interest.  I checked and made sure that I have all the correct capitalization.  "Hot" is not "HOT" or "hot", ands so on for the full name.  The script still crashed at the same point.

As it turned out, the actual name of the helo in DCS was not "Hot LZ Mi-24P-1" but was "Hot LZ Mi-24P-1 ".  That "space" at the end of the name in DCS is a killer and was not so easily found.

 

Lesson learned - Names are strings, including any trailing spaces!

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

Posted
2 hours ago, Chump said:

Always trim your strings, my friend! 🙂 Glad you got it working.

I think I know what this means, but i am not Lua advanced enough (yet!) to be sure, or to even start to implement.

 

Would that work with the name of the Group in DCS with a trailing space?

 

PS - Thanks for the response)

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

Posted

There is no native function for trimming in lua. You more or less have to do something like s = string.gsub(s, " ", "")

 

However that isn't really useful when you named the group as something with a space in it because it'll still fail Group.getByName("whatever") when the group is actually named "whatever ". Best sanity check is to click on the group name in the editor and Ctrl+A to select all of the text then copy and paste that into the line that keeps failing. Should at least make it obvious if spaces exist. 

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted

Thanks for the advice.  I think I have learned to double check the names in DCS ME to make sure there are not trailing spaces.

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

Posted (edited)
13 hours ago, AKA_Clutter said:

The other day I spent at least an hour and a half chasing a bug.  I'm sure I am not alone, nor will this be the last bug to chase.  IIRC, Lua sees spaces at the end of a line as white noise.  

 

[]

As it turned out, the actual name of the helo in DCS was not "Hot LZ Mi-24P-1" but was "Hot LZ Mi-24P-1 ".  That "space" at the end of the name in DCS is a killer and was not so easily found.

 

Lesson learned - Names are strings, including any trailing spaces!

 

I believe it's one of those lessons that everyone has to learn at some time - that there in an abstraction layer between a computing language that formulates an algorithm, and the data that the algorithm works on. This distinction is by no means trivial, and it is further muddled by the fact that both reside in the same memory and that at first the distinction seems arbitrary.

 

When I started programming (shortly before the great flood, when Dinosaurs roamed the land), programming languages (well, the ones I started on) where not case sensitive. And of course it was a rude awakening to me that although the program source wasn't case sensitive, comparing the data it operated on was: the data string "Hi There" was not equal to "HI THERE". It took me some time to understand that data is separate from the algorithms that work on them, and I don't think that there is a short cut you can take; you'll have to experience it yourself. 

 

Data is just that: bytes. And there is usually no inherent transformation, rule, simplification or other implied whatchamacallit applied to data that might apply to the source that you used to formulate the algorithm. A German "ü" will not automatically match the Latin "u". Lower case doesn't match upper case unless you explicitly transform the data yourself. And leading and trailing blanks are, from the computer's perspective, simply bytes that have neither more nor less meaning than a leading or trailing character or digit. Similar Issues involve the distinctions between 'nil' (reference), "nil" (the string consisting of the characters 'n', 'i', and 'l'), zero (the floating point number), zero (the integer, not in Lua), 'null' (value returned from a data base, not in DCS Lua), the character located at position zero in the character table, the character '0', the string "0", an empty string, and false (the Boolean value). Joy over joy 🙂 

 

In DCS term that means that when comparing strings you will make your life easier if you 'sanity-convert'

  • convert whitespace to blanks (whitespace are tabs, line feed, carriage return and other invisible characters)
  • strip leading and trailing blanks
  • remove diacritical marks (dots above and below letters ü->u, accents ê->e, circumflex ñ->n etc)
  • convert all to lower OR upper case 

before you compare them. Of course (not required in DCS) it gets even worse if you work with network URLs and similar, as you must escape/unescape special characters (e.g. %20 for blank), so there's a whole paradise of additional challenges.   

 

Edited by cfrag
Posted

The sad but true thing to take away from this that I had a mission open that I was testing scripts out when I saw the thread and replied. In that time I added spaces to a zone name to verify select all in the text box worked how I thought it would. Grabbed dinner, played some RDR2, and sat back down to finish up what I was doing earlier. I forgot I had added the spaces. Took a few attempts to realize I added the spaces earlier, saved it, and forgot all about it. 

  • Like 1

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Posted
7 hours ago, Grimes said:

The sad but true thing to take away from this that I had a mission open that I was testing scripts out when I saw the thread and replied. In that time I added spaces to a zone name to verify select all in the text box worked how I thought it would. Grabbed dinner, played some RDR2, and sat back down to finish up what I was doing earlier. I forgot I had added the spaces. Took a few attempts to realize I added the spaces earlier, saved it, and forgot all about it. 

LOL  Sorry testing for me caused you some lost time.  I'm just starting down the road of scripting for DCS, learning Lua and C++, so I think that I will have many more such "moments"

----------------

AKA_Clutter

 

Win 10 Pro, Intel i7 12700k @4.6 GHz, EVGA RTX 3080  FTW, Ultra 64 GB G.Skill DDR4 3600 RAM, Acer 27" flat screen, HP Reverb G2, TM Warthog HOTAS with Virpil warBRD base, MFG Rudder Pedals, Virpil TCS Rotor Base with AH-64Dcollective, TrackIR 5 Pro w/Vector Expansion, PointCTRL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...