ID:1885673
 
(See the best response by Kaiochao.)
Im trying to code a system where based on the button clicked it does various things based off the buttons name like if(button is named cookie) then usr<<"I haz a cookie" kind of thing but I have no clue how to make it grab the name of the button

Code:
    HotkeySetter()
set hidden=1
if(winget(usr,"hotkey1","name;hotkey1"))
usr<<"hotkeyx"
if(winget(usr,"hotkey2","name;hotkey2"))
usr<<"hotkey2"


and yes its a verb only prob is when i press either button both messages show up when I want it to only show the approved message if im clicking the right named button



Best response
Off the top of my head, you should be able to grab the ID of the button clicked by checking for the control with focus:
winget(player, null, "focus")

It may not be accurate if there's a lot of lag and the player clicks around quickly.
nope didnt fix it everytime i click a button it still says both things
In response to Mastergamerx
You should try outputting the winget(). Also, show your code when you change it.
  HotkeySetter()
set hidden=1
if(winget(usr, null, "focus"))
usr<<"hotkeyx"
if(winget(usr, null, "focus")))
usr<<"hotkey2"

not much a change to show
In response to Mastergamerx
Do you know what winget() does?
Use winget() to get the "text" param of the button. Use switch() to check what the text is, and execute your code afterwards.
what do you mean switch show me a example i dont get it?
In response to Mastergamerx
mob
verb
getButton()
switch(winget(src, "default.testbutton", "text"))
if("Attack")
src << "This button says Attack! Let's change it to say Defend!"
winset(src, "default.testbutton", "text=\"Defend\"")
if("Defend")
src << "This button says Defend! Let's change it to say Attack!"
winset(src, "default.testbutton", "text=\"Attack\"")
i tried it but it keep saying hotkey 2 even though im pressing the first button and it's text is 1

    HotkeySetter()
set hidden=1
switch(winget(src, "hotkey", "text"))
if("1")
src<<"hotkey1"
if("2")
src<<"hotkey2"


Are you changing the text param of the button at all?

If you...
winset(src, "[window id].[button name]", "text=\"[button text]\"")

That will change the text that's shown on the button to whatever you replace [button text] with.

How are you setting up your Hot-Key system? How does it determine what key you're pressing and call the command based on that key?
ok here is a terrible mockup totally wrong codedexample of what im trying to do
    HotkeySetter()
set hidden=1
switch(winget(src, "hotkey", "text"))
if("hotkey1")
switch(list("pick a technique to set",(src.learnedtechs)))
Hotkey1="whateverIpicked"
if("hotkey2")
switch(list("pick a technique to set",(src.learnedtechs)))
Hotkey2="whateverIpicked"


then of course the macro would call the verb which then does this

    Hotkey1()
// set hidden=1
if(findtext("[Hotkey1]","Earth Shards",1))
spawn() src.Earth_Shards()
else
usr<<"tech Not Found"
return


which hotkey1 var would be set to w/e u picked form pressing the button which brought up the tech list which u chose from to which set the var. Hopefully I explained this good
In response to Mastergamerx
I think something like this is what you're looking for:
mob
var
list
hotkeys[] = list()
verb
changeHotKey(key as text, command as text)
src.hotkeys[key] = text2path("/mob/verb/[command]")
winset(src, key, "parent=macro;name=[key];command=useHotKey+[key]")

useHotKey(key as text)
call(src, src.hotkeys[key])()

this()
world << "This"
that()
world << "That"
quite intriguing design but how would i do it where it would display a list of techs instead of typing them in to set it
In response to Mastergamerx
To show "techs" you could for() loop through your list of "techs" and output them to a grid, or if you want the generic cheapo alert-box style, just input() as list to the player.
Ok so I finally managed to get it 98% done to how i want it expect 2 problems I'm having. 1. I want it to grab the verb based on the name="" var ive given the verb so I can have spaces but no Idea how to do it. and 2. I want it to show the only item in the list and not just automatically set it as default
    verb
Hotkey1()
set hidden=1
call(src,text2path("/mob/verb/[Hotkey1]"))()

gettech()
src.learnedtech+=copytext("Earth Shards",1)
src.learnedtech+=copytext("Windmill",1)


HotkeySetter1()
Hotkey1=input(usr,"Which tech do you want to set?")in src.learnedtech


this is the name var I want to grab so I dont have to put "Earth_Shards" for the copy text just to get it to work
    Earth_Shards()

name="Earth Shards"
src.learnedtech+=copytext("Earth Shards",1)
src.learnedtech+=copytext("Windmill",1)




You realize that copytext("Earth Shards",1) is exactly the same thing, but slower than "Earth Shards", right?

second:

call(src,text2path("/mob/verb/[Hotkey1]"))()


Should probably just be:

call(src,Hotkey1)()


where Hotkey1 should be set to the verb name.

Even better:

var
list/hotkeys
list/knowntech
verb
Hotkey(index as num)
set hidden = 1
if(hotkeys&&hotkeys[index])
call(src,hotkeys[index])()
setHotkey(index as num)
set hidden = 1
hotkeys[index] = input(usr,"Which tech do you want to set?") in knowntech


Though you might jam a try/catch() in there a few places.