[WAD+TWEAK] LUA - ScenEdit_HostUnitToParent issue

Post bug reports and ask for game support here.

Moderator: MOD_Command

Post Reply
Bashkire
Posts: 81
Joined: Mon Feb 23, 2015 6:28 pm

[WAD+TWEAK] LUA - ScenEdit_HostUnitToParent issue

Post by Bashkire »

Hello, me again. This is getting to become an embarrassing habit now.

ScenEdit_HostUnitToParent allows for two different parameters:
  • SelectedHostNameOrID - This teleports the designated unit to the specified port and assigns it as the new base port, and
  • SelectedBaseNameOrID - This should assign the designated unit to the specified port without moving it there instantly.
Attached is a save with one ship and two ports.
Paste the below code into the LUA console and you'll see the error "SelectedHostNameOrID has not been defined!" which is rather odd seeing as I'm using "base" rather than "host".

Code: Select all

unit_ship1 = ScenEdit_GetUnit({side = "Side A", name = "Ship 1"})
guid_ship1 = unit_ship1.guid

base_portB = ScenEdit_GetUnit({side = "Side A", name = "Port B"})
guid_portB = base_portB.guid

rebase_Ship1 = ScenEdit_HostUnitToParent({HostedUnitNameOrID = ship1, SelectedBaseNameOrID = portB})
Cheers all.
Rebase Test.zip
(7.11 KiB) Downloaded 27 times
User avatar
Deserere
Posts: 559
Joined: Wed Oct 13, 2021 1:15 pm

Re: LUA - ScenEdit_HostUnitToParent issue

Post by Deserere »

Logged 0014955
Si Spiritus pro nobis, quis contra nos?
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: LUA - ScenEdit_HostUnitToParent issue

Post by KnightHawk75 »

User error.
Correct code should be:

Code: Select all

rebase_Ship1 = ScenEdit_HostUnitToParent({HostedUnitNameOrID = unit_ship1.guid, SelectedHostNameOrID = base_portB.guid})
-both the parameter name is wrong, and parameter content is wrong (being fed objects and not names or guids) in the original code.

docs are correct:
http://commandlua.github.io/index.html#table_HostUnit
User avatar
michaelm75au
Posts: 12463
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: LUA - ScenEdit_HostUnitToParent issue

Post by michaelm75au »

I have tweaked this method somewhat.

I have added alias names to the parameters which may make it a bit clear. You can use the current names or these.
ScenEdit_HostUnitToParent( {UnitName = ..., HostBaseNameOrID =..., AssignedBaseName = ....})
You will be able to add both 'bases' in the same command. I will update docs to make the distinction between HostBase (where the unit is parked/docked) and AssignedBase (where the unit calls home).

The result of the command will be a single boolean as currently if you only supply one base. If you give it both base parameters, you will get a list containing the 2 status values.

Code: Select all

local unit_ship1 = ScenEdit_GetUnit({side = "Side A", name = "Ship 1"}) 
local guid_ship1 = unit_ship1.guid 

local base_portA = ScenEdit_GetUnit({side = "Side A", name = "Port A"}) 
local base_portB = ScenEdit_GetUnit({side = "Side A", name = "Port B"}) 

local rebase_Ship1 = ScenEdit_HostUnitToParent({unitname = unit_ship1.guid,  AssignedBaseNameOrID = base_portA.guid})
if type(rebase_Ship1) == 'boolean' then
   print(tostring(rebase_Ship1))
else
   print(tostring(rebase_Ship1[0]) .. ' ' .. tostring(rebase_Ship1[1]))
end
Michael
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: LUA - ScenEdit_HostUnitToParent issue

Post by KnightHawk75 »

"You will be able to add both 'bases' in the same command. "

I think you just made things more confusing by adding base 'assignment' features into a function that never seemed aimed at that, it's HostUnitToParent after all (ie "insert this into that"). :?

Ie past to insert/host.. it was

Code: Select all

rebase_Ship1 = ScenEdit_HostUnitToParent({HostedUnitNameOrID = unit_ship1.guid, SelectedHostNameOrID = base_portB.guid})
to assign... it has been set base property to base wrapper (assume still is..)

Code: Select all

unit_ship1.base = base_portB;
:? Always seemed pretty clear to me.
User avatar
michaelm75au
Posts: 12463
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: LUA - ScenEdit_HostUnitToParent issue

Post by michaelm75au »

The 3rd parameter was always there. But it wasn't clear exactly what it meant.
I think most use of the function revolves around just the first 2 parameters anyway and that has not changed. As you say there is an easier way to 'assign' a unit to a base.
Michael
Post Reply

Return to “Tech Support”