fire state, move state and other toggle commands

fire state, move state and other toggle commands

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

fire state, move state and other toggle commands

Post by smoth »

Fire and move state both are in GetUnitStates but I see no way to add my own custom mode toggles with a add unit state etc..

Is there a table for the unit states? or are they hard coded to the engine? because right now the latter seems to be true(of course my engine source is a bit old).

If it is hard coded to the engine, is there another way of reading the current fire and move states? Because I am working on code to better handle custom commands and this is a point I am stuck at.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: fire state, move state and other toggle commands

Post by jK »

local cmdDesc = {
...
type = CMDTYPE.ICON_MODE,
params = {'0', 'Cloaker Off', 'Cloaker On' } -- first '0' indicates the default state (here 'Cloaker Off')
}
Spring.InsertUnitCmdDesc(unitID, 0, cmdDesc)
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: fire state, move state and other toggle commands

Post by smoth »

Yet my command is missing from the unit states returned by the get callin


I'll double check my command code when I get home
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: fire state, move state and other toggle commands

Post by FLOZi »

I think the OP is correct, Smoth iirc-off-the-top-of-my-head.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: fire state, move state and other toggle commands

Post by smoth »

flozi, is there a different way to handle fire/move state? If so, it would be good to know because I am trying to clean up the feature placer code and one of the big issues I found is handling CMDTYPE.ICON_MODE
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: fire state, move state and other toggle commands

Post by knorke »

Spring.GetUnitStates

( number unitID ) -> nil | {
"firestate" = number,
"movestate" = number,
"repeat" = boolean,
"cloak" = boolean,
"active" = boolean,
"trajectory" = boolean,
["autoland" = boolean,]
["autorepairlevel" = number,]
["loopbackattack" = boolean]
}
doesnt seem like it can read custom toggle buttons.
seems if you make your own toggle button, you have to save that state yourself? maybe in a table or better in UnitRules.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: fire state, move state and other toggle commands

Post by smoth »

so there is no way to add to unit state? was this by design or forgotten? because it seems like it wasn't intended
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: fire state, move state and other toggle commands

Post by jK »

There are no unit states! There is no code in the engine that `manages` CMDTYPE.ICON_MODE. All code catches such commands in `AllowCommand` and even has to update the CmdDesc itself (switching the state of the button).
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: fire state, move state and other toggle commands

Post by smoth »

jK wrote:There are no unit states!
What i am talking about are the values returned by GetUnitStates(). Are you talking something lower level than this?
jK wrote:There is no code in the engine that `manages` CMDTYPE.ICON_MODE. All code catches such commands in `AllowCommand` and even has to update the CmdDesc itself (switching the state of the button).
when I want to find out the fire mode of a unit I use:
GetUnitStates(unitID)["firestate"]

which returns 1 or 2 or 3.

This I use to get the mode of the FIRE_STATE command.

in my own ICON_MODE commands I use

local spreadCMD = CMD["FSPREAD"]
GetUnitCmdDescs(unitID, spreadCMDID)[1].params[1])

Why is my spread command not returned as a result in GetUnitStates? Should I be using GetUnitCmdDescs instead of GetUnitStates for FIRE_STATE instead?

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


Why are there two functions:
Spring.GetUnitCmdDescs()
Spring.GetUnitStates()

there must be a reason.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: fire state, move state and other toggle commands

Post by jK »

As said there are no unitstates!
Spring.GetUnitStates() gathers them from several places across the engine!
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: fire state, move state and other toggle commands

Post by smoth »

so why have it?
User avatar
Pressure Line
Posts: 2283
Joined: 21 May 2007, 02:09

Re: fire state, move state and other toggle commands

Post by Pressure Line »

when I want to find out the fire mode of a unit I use:
GetUnitStates(unitID)["firestate"]

which returns 1 or 2 or 3.

This I use to get the mode of the FIRE_STATE command.

in my own ICON_MODE commands I use

local spreadCMD = CMD["FSPREAD"]
GetUnitCmdDescs(unitID, spreadCMDID)[1].params[1])
Why is my spread command not returned as a result in GetUnitStates?
Short answer: Because it's not.
Long answer: because GetUnitStates grabs "from several places across the engine" some of the 'states' of the hardcoded command buttons, which would otherwise be a pain in the rear to get. But for custom commands you have to get them yourself
Post Reply

Return to “Lua Scripts”