Page 1 of 1

Cmd Desc cycle both ways and assign states to keybind?

Posted: 18 Jul 2013, 20:49
by Zealot
Here is the gadget I am working on:

http://pastebin.com/BesqZgMC


Has anyone implement a way to cycle through a 3 state cmd desc button both forwards and backwards?


Also could some one point me in the right direction to assign each state of the cmd desc to a keybind?

I assume i should use the Lua callin "KeyPress()"

where in the gadget should I insert this?

Should I put it at the very bottom of the gadget code?

Gadget code with my first stab in the dark at coding keybinds to the comand:
http://pastebin.com/nTHRgnfV


The below code is what I added to attempt to make a keybind:

I would have to repeat this for each key i wanted to bind.
This is obviously needs work.
I don't know if there is a callin to give the id of what units the player has selected at a given time?

I have wrtten some pseudo code at the top to describe the steps i think need to be taken.

Code: Select all

   -------[[Keypress callin for reference:
KeyPress() --> "key, mods, isRepeat", where key = keymap, mods = SHIFT, etc.]]---

 ---------------how to write no mods? "false"?
 ------what does "isRepeat" do?

 --press the "y" letter on kb
--check if any units are selected by player
---are selected units on the units in the list of units that have the cmd --desc button.
--
--set the state of the button the state bound to that key

 function Gadget:KeyPress(y,false, false) 
    if unitselected then                      --what is the callin for this
          if STANCE[unitDefID] then  
  	     local cmdDescID =FindUnitCmdDesc(unitID,CMD_STANCE)
  			cmdDescID.cmdParams[1] = 1 
		end
	end  
  end
  
Thanks for help with this and thanks for all the help I have received so far.

Re: Cmd Desc cycle both ways and assign states to keybind?

Posted: 19 Jul 2013, 03:48
by CarRepairer
Don't use keypress. Add "actions" by using widgethandler.addaction. You and the user can then bind keys to the action. You can make one action to go to the next state and one to go to the previous.

Re: Cmd Desc cycle both ways and assign states to keybind?

Posted: 20 Jul 2013, 18:52
by Google_Frog
Here is a gadget which implements a 4 state toggle with forwards and backwards. http://code.google.com/p/zero-k/source/ ... r_dive.lua

Re: Cmd Desc cycle both ways and assign states to keybind?

Posted: 21 Jul 2013, 12:22
by Zealot
Thanks guys.

Ill get on to that later this week.

Spent all day today recoding unit voices with a voice actor.