Trying to understand Forms

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

Post Reply
Ditto
Giant
Posts: 179
Joined: Thu Jul 28, 2011 1:06 pm

Trying to understand Forms

Post by Ditto »

I'm having some trouble working with Forms and reading the input via MacroLinkText ..

Here's a simple example:

create a lib token named: "Lib:Utility"

on that token, create a new button, and place following code in it:

Code: Select all

[h, if( isFrameVisible("myHand") ), code: {}; { [resetFrame("myHand")] } ]

[frame("myHand"): {
   [h: processorLink = macroLinkText("processForm@Lib:Utility", "all")]

   <form action="[r:processorLink]" method="json">
      <input type="submit" name="B1" value="1">
      <input type="submit" name="B2" value="2">
      <input type="submit" name="B3" value="3">
   </form>
}]
create another macro: "processForm" and place this code in it.

Code: Select all

[r: macro.args ]
Ok, so all I need to know is which button was clicked on.
The full example I'm trying to handle is a frame with several image buttons (ie cards).
The player would click on a card, and then some code would fire.

So I need to know:
1) which player triggered the event (still not sure how I'm going to do that - perhaps getImpersonatedName or such ??)
2) which card they clicked on. the problem with this one, is that the code returns only:

Code: Select all

{"B2"."2"}
but I can't access that with [json.get ( arg, "B2") ] since I don't know it's B2 that was clicked .. O.o
I tried to name all the buttons the same:

Code: Select all

      <input type="submit" name="B" value="1">
      <input type="submit" name="B" value="2">
      <input type="submit" name="B" value="3">

Then I could just ask for:

Code: Select all

[json.get ( arg, "B")]
.. which would work fine .. unfortunately, when they are the same name, they seem to "overwrite" each other .. and I always get

Code: Select all

value=3
, regardless of which button was clicked.

What's the simplest way to get that value without knowing which button was clicked ?

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Trying to understand Forms

Post by wolph42 »

I dont 'have the answer to your latter question by hand, but it should be doable, the former though: Wiki: getPlayerName()

edit: what you can do is give the three buttons a different name and then check which one was pressed by using Wiki: json.contains()

Ditto
Giant
Posts: 179
Joined: Thu Jul 28, 2011 1:06 pm

Re: Trying to understand Forms

Post by Ditto »

wolph42 wrote:I dont 'have the answer to your latter question by hand, but it should be doable, the former though: Wiki: getPlayerName()

edit: what you can do is give the three buttons a different name and then check which one was pressed by using Wiki: json.contains()
Thanks Wolph .. you are a bottomless pit of information! :)

Hey, re: getPlayerName. So I take it that gives the name of the user logged into Maptools ?
Regardless of Token ..

whereas, getImpersonated, would give me the token being impersonated .. correct ?
[edit] so yeah, just tested, getImpersonated is what I want, I want the token they're impersonating :) [/edit]

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

json.contains .. ahh, still getting used to all these json functions .. I'll try that one .. thanks!

There isn't a simple way of just turning that json array into a straight string, is there ?
If I could, I could just rip out the first button name, since it'll always be in the same location :)

I tried: [json.get ( arr, 0 )] ... but that doesn't work .. so I'm thinking, if I can treat it as a string, not a json array, I might be able to rip out what I need ??

[edit2] .. and a little more messing around, I think I got what I wanted:

Code: Select all

json.get ( macro.args, json.fields( macro.args) )]
Thanks Wolph! You reminded me there's a s**t-ton of functions for json arrays !! :)

[/edit]


Post Reply

Return to “Macros”