Page 1 of 1

[FIXED] Question about .manualAltitude wth Submarines & .moveto property

Posted: Sat Apr 18, 2020 7:13 pm
by KnightHawk75
CMO Build 1142.2

So I noticed when trying the unit wrapper .moveto property it throws an error.
Not sure what I'm doing wrong to access\set this property?

Code: Select all

 local tbl;
 --tbl = {type = 'Submarine', name = 'SSN-802 single', dbid = 554, side = 'Blue',
 --loadoutid = 0,heading = 0, Latitude="S4.50.00",Longitude="W10.00.00",
 --autodetectable="false",holdfire="true",proficiency=4,speed=0,depth=0,altitude=0};
 
 tbl = {type = 'Aircraft', name = 'F-22', dbid = 3821, side = 'Blue',loadoutid = 4526,
 heading = 0, Latitude="S2.50.00",Longitude="W10.00.00",autodetectable="false",
 holdfire="true",proficiency=4,speed=0,depth=0,altitude=12000};
 
 local u = ScenEdit_AddUnit(tbl);
 u.moveto = false;
 --u.moveto = 'false';-- same error
 --u.moveto = 'No'; -same error
 --print(tostring(u.moveto)) -- function address luaNet_function: 49A3B028
 --print(u.moveto); --KeraLua.LuaFunction
 
The casting exception:

Code: Select all

 System.InvalidCastException: 
 Unable to cast object of type 'KeraLua.LuaFunction' to type 
 'System.Reflection.MemberInfo'.at NLua.MetaFunctions.TrySetMember
 (Lua luaState, ProxyType targetType, Object target, BindingFlags 
 bindingType, String& detailMessage) at NLua.MetaFunctions.
 SetFieldOrPropertyInternal(Lua luaState)
 at NLua.MetaFunctions.SetFieldOrProperty(IntPtr state)
 at KeraLua.NativeMethods.lua_pcallk(IntPtr luaState, 
 Int32 nargs, Int32 nresults, 
 Int32 errorfunc, IntPtr ctx, IntPtr k)
 at NLua.Lua.DoString(String chunk, String chunkName)
 at Command_Core.Lua.LuaSandBox.RunScript(String str, Boolean RunInteractively,
 String script),nil
 

Also when trying to use .manualAltitude when feeding it anything other than 'off',
'current','desired', I get no results \ change, other than the default 20 meters\-66 ft.

Code: Select all

 local tbl;
 tbl = {type = 'Submarine', name = 'SSN-802 single', dbid = 554,
 side = 'Blue', loadoutid = 0,heading = 0, Latitude="S4.50.00",
 Longitude="W10.00.00", autodetectable="false",holdfire="true",
 proficiency=4,speed=0,depth=0,altitude=0};
 
 --    tbl = {type = 'Aircraft', name = 'F-22', dbid = 3821, side = 'Blue',
 --    loadoutid = 4526, heading = 0, Latitude="S2.50.00",Longitude="W10.00.00",
 --    autodetectable="false",holdfire="true",proficiency=4,
 --    speed=0,depth=0,altitude=11000};
 
   local u = ScenEdit_AddUnit(tbl);
   print(tostring(u.manualAltitude)); --nil expected i guess? 
   u.manualAltitude = -100; print(u.manualAltitude);
   u.manualAltitude = '-100 FT'; print(u.manualAltitude);
   u.manualAltitude = 6; print(u.manualAltitude); --surface code for subs?
   u.manualAltitude = -6; print(u.manualAltitude); 
   u.manualAltitude = '-100'; print(u.manualAltitude);
   u.manualAltitude = 'OVERLAYER'; print(u.manualAltitude); --change for air 
   u.manualAltitude = 'Surface'; print(u.manualAltitude); --change for air
   u.manualAltitude = 'Off';  print(u.manualAltitude);
 

Works entire as expected with aircraft however, just not with subs.

Also found cases where using ScenEdit_SetUnit() throws the follow errors where
I don't understand why it's doing so, when any preset keywords are used other then
current,desired, or off, however unlike the above supplying numbers or text form of
number does work.

Code: Select all

 local tbl;
 
   tbl = { type = 'Submarine', name = 'SSN-802 single', dbid = 554,
   side = 'Blue',loadoutid = 0,heading = 0, Latitude="S4.50.00",
   Longitude="W10.00.00", autodetectable="false",holdfire="true",
   proficiency=4,speed=0,depth=0,altitude=0 };
 
   local u = ScenEdit_AddUnit(tbl);
   print(u.manualAltitude);
   u= ScenEdit_SetUnit({guid=u.guid,moveto=false,manualAltitude=0});
   print(u.manualAltitude);
   u= ScenEdit_SetUnit({guid=u.guid,moveto=true,manualAltitude=6});
   print(u.manualAltitude);
   u= ScenEdit_SetUnit({guid=u.guid,moveto=false,manualAltitude=-90});
   print(u.manualAltitude);
   u= ScenEdit_SetUnit({guid=u.guid,moveto=false,manualAltitude='6'});
   print(u.manualAltitude);
   u= ScenEdit_SetUnit({guid=u.guid,moveto=false,manualAltitude='-100'});
   print(u.manualAltitude);
   u= ScenEdit_SetUnit({guid=u.guid,moveto=false,manualAltitude='-90 FT'});
   print(u.manualAltitude);
   u= ScenEdit_SetUnit({guid=u.guid,moveto=false,manualAltitude='Off'});
   print(u.manualAltitude);
 

Code: Select all

 --- examples that throws errors
   u= ScenEdit_SetUnit({guid=u.guid,moveto=false,manualAltitude='Overlayer'}); 
 -- print(u.manualAltitude);
 -- u= ScenEdit_SetUnit({guid=u.guid,moveto=false,manualAltitude='Surface'});
 -- print(u.manualAltitude);
 -- u= ScenEdit_SetUnit({guid=u.guid,moveto=false,manualAltitude="Underlayer"});
 -- print(u.manualAltitude);
 
 ERROR: Unable to cast object of type 'Command_Core.Submarine'
 to type 'Command_Core.Aircraft'.
 


Again only problematic on subs when using the keywords, on aircraft with the right keywords
for aircraft they work.

Sort of besides the point but the simple thing I was trying to do, spawn sub that
would not start going to default desired -66 feet upon pressing play via,
when I ran into the above.

Code: Select all

 u = addunit ({bla, bla ,etc, altitude = 0})
 u.moveto = false 
 u.manualAltitude = 'off'

I know the workaround is to do this instead, but something seems wrong
with manualAltitude and subs.

Code: Select all

 u = addunit({bla,bla, bla,altitude=0});
 u=setunit({guid= u.guid,moveto=true,manualAltitude='Off',depth=u.altitude}) 
 

Edit: Added attachment for the post in .txt form due to formatting.
..never-mind fixed post formatting I think.

RE: Question about .manualAltitude wth Submarines & .moveto property

Posted: Sat Apr 18, 2020 10:50 pm
by michaelm75au
'moveto' is not defined for the unit wrapper. This just controls whether the change in speed/alt is instant or gradual. Setting 'manual' in the wrapper is always gradual as it sets the 'desired' speed/alt and not the current ones.

Something IS off.
For "ScenEdit_SetUnit({name = 'SSN-802 single', side = 'Usa', manualaltitude='over'})", the 'manualatitude' is working for subs despite the "ERROR: Unable to cast object of type 'Command_Core.Submarine' to type 'Command_Core.Aircraft'"

Watching the sidebar, I can see the altitude change.

This was working originally. Something has changed so I need to check it.

I have found a couple of errors but they seem to have been there for sometime so maybe this function is not used often?

I'll make the corrections and do some testing on combinations.

RE: Question about .manualAltitude wth Submarines & .moveto property

Posted: Sun Apr 19, 2020 12:10 am
by michaelm75au
Logged 0013839

RE: Question about .manualAltitude wth Submarines & .moveto property

Posted: Sun Apr 19, 2020 12:29 am
by KnightHawk75
ORIGINAL: michaelm75au

'moveto' is not defined for the unit wrapper.

Something IS off.
For "ScenEdit_SetUnit({name = 'SSN-802 single', side = 'Usa', manualaltitude='over'})", the 'manualatitude' is working for subs despite the "ERROR: Unable to cast object of type 'Command_Core.Submarine' to type 'Command_Core.Aircraft'"

Watching the sidebar, I can see the altitude change.

This was working originally. Something has changed so I need to check it.

I have found a couple of errors but they seem to have been there for sometime so maybe this function is not used often?

I'll make the corrections and do some testing on combinations.
Thanks for looking into it, I tend to agree that at some point the manualaltitude direct, and the named preset keywords in setunit were working, I don't use keywords often, but I could swear I've used 'Surface' before without generating errors.

RE: Question about .manualAltitude wth Submarines & .moveto property

Posted: Sun Apr 19, 2020 4:08 am
by Dimitris
Fixed for the next update release.