Nivekk / KOS

Fully programmable autopilot mod for KSP.
Other
80 stars 30 forks source link

Lock fails when the variable name has uppercase letters in it. #197

Closed Dunbaratu closed 10 years ago

Dunbaratu commented 10 years ago

I think I may have part of the answer to why some people have been claiming lock variables work correctly and others have been claiming they don't. It's an issue of case sensitivity. If you use variable names that are all lowercase it works, but if you have a capital letter in the name it doesn't. Here's a tiny example code that proves it (run under 0.9) :

The only difference between these two example programs is that the first one calls the variable "mytime" and the second one calls it "myTime" with a capital "T". Other than that the two are identical:

// program lockLower:
lock mytime to time + 10.

set i to 0.
until i=4 {
  print "Ten seconds from now, time will be " + mytime.
  wait 1.
  set i to i + 1.
}.
// program lockUpper:
lock myTime to time + 10.

set i to 0.
until i=4 {
  print "Ten seconds from now, time will be " + myTime.
  wait 1.
  set i to i + 1.
}.

When I tested them, I got this:

unlock all.
run lockLower.
Ten seconds from now, time will be 47202805
Ten seconds from now, time will be 47202806
Ten seconds from now, time will be 47202807
Ten seconds from now, time will be 47202808
unlock all.
run lockUpper.
Ten seconds from now, time will be 47202808
Ten seconds from now, time will be 47202808
Ten seconds from now, time will be 47202808
Ten seconds from now, time will be 47202808

When running lockUpper, the value wasn't changing. If I toggle the power on the SCS unit to clear all memory, and then run lockUpper first, then I get all zeros because lockLower hadn't set the value of mytime yet.

I suspect that behind the scenes the variable name is being converted to an all-lowercase key, but the conversion isn't happening everywhere consistently, and somewhere within the logic of the lock command one of the places where the conversion needed to happen got missed. So the lookup only works in the case where the raw name and the converted name are a match because it was lowercase to begin with.

Nivekk commented 10 years ago

Okay, I've pushed a change that should now fix this. Thank you for helping to track it down!

Dunbaratu commented 10 years ago

Well, I did have an ulterior motive in tracking it down - I couldn't figure out how to get my script to work until I figured out some workaround for the lock problem.

Thanks for the fix. I already changed all my code to remove the CamelCase on variable names so it would work, but this should help others who have been having problems.