Jump to content

MultipleChoice input


Wegge

Recommended Posts

Is it possible to get the selection from a MultipleChoice input as something else than a string?

 

I'm trying to work around the limitations on the number of visible zones, by giving the player a Yellow-Pages item, where he/she can select the destination to go to. It works, but I end up with a lot of repetitions:

 

zinputVisVejTil = Wherigo.ZInput(cartPakkenTheParcel)
zinputVisVejTil.Id = "61b25265d6163eaa054ef91d00d49c1a"
zinputVisVejTil.Name = "VisVejTil"
zinputVisVejTil.InputType = "MultipleChoice"
zinputVisVejTil.Choices = {"Supermarket","DIY store","Mason","Carpenter", ...)
zinputVisVejTil.Visible = true

 

And at handling function, I have to repeat this:

 

function zitemVejviser:OnVisvejtil(input)
 if (input == "Supermarket") then
   zoneSupermarket.Active = true
   zoneSupermarket.Visible = true
 end

 if (input == "DIY store") then
   zoneDIY.Active = true
   zoneDIY.Visible = true
 end

 if (input == "Mason") then
   zoneMason.Active = true
   zoneMason.Visible = true
 end

 if (input == "Carpenter") then
   zoneCarpenter.Active = true
   zoneCarpenter.Visible = true
 end

 ...

end

 

While this works, it's error prone. So my question is: Is it possible to pack an object reference into the command? In my ideal world, it would be possible to specify a table for the input like this:

 

zinputVisVejTil.Choices = {{Text = "Supermarket", Obj = zoneSupermarket},
                          {Text = "DIY store", Obj = zoneDIY},
                          {Text = "Mason", Obj = zoneMason},
                          {Text = "Carpenter", Obj = zoneCarpenter}, 
                          ...
                         }

 

With a construct like this, my coding could be a lot simpler. But so far, all of my efforts to find a way to do this have been in vain. Is it possible, or should I go and look for a way to create the commandlist at runtime instead, and make my own mapping table?

Link to comment

what you are attempting will not work.

 

however, there are ways. let me show you a magic piece of code going into your OnGetInput method

local options = {}
options["Supermarket"] = zoneSupermarket
options["DIY store"] = zoneDIYstore
options["Mason"] = zoneMason
-- ....

local zone = options[input]
zone.Active = true

 

(By the way, you don't need to set zone visibility unless you are hiding them! It's not like inactive zones forget everything. You can keep a zone visible forever and just toggle active on/off. Inactive zone is not used by the player so it won't be displayed.)

 

There are even more drastic ways to do this. This goes in the function where you call GetInput:

local zonesInYellowPages = {zoneSupermarket, zoneDIYstore, zoneMason, ...... }
mapping = {}
zinputWhatever.Choices = {}
for k,zone in ipairs(zonesInYellowPages) do
  mapping[zone.Name] = zone
  table.insert(zinputWhatever.Choices, zone.Name)
end

and this goes into OnGetInput:

local zone = mapping[input]
zone.Active = true

 

(FWIW, zinputs are fake objects. if you're writing code by hand, you don't need to create the multiple-choice in builder, you can just write this:

Wherigo.GetInput {Text="Pick one", Media=zmediaBla, InputType="MultipleChoices", Choices=choices}

)

Link to comment

To my knowledge, all inputs return primitive types. I'd like to suggest you design a function that takes an input's type and returns a table or whatever you'd like instead of the string. Thus, there would be only one function that is assigned the responsibility of deciphering what the user selected. You could also have a function that, when the cartridge starts or before the input is used, assigns the input's choices from the text property of your table.

Link to comment

Also, i'm apparently dumb because you apparently know that you can "make my own mapping table". I skipped over that part and assumed that you didn't know about the possibility. Sorry.

Yes, that's the only way to do it. Inputs always return strings, or nil if they are cancelled. (but cancelling inputs can crash garmins, so it's not like you need to solve that possibility)

 

Oh well. At least here's some code to get you started.

Link to comment

Also, i'm apparently dumb because you apparently know that you can "make my own mapping table". I skipped over that part and assumed that you didn't know about the possibility. Sorry.

Yes, that's the only way to do it. Inputs always return strings, or nil if they are cancelled. (but cancelling inputs can crash garmins, so it's not like you need to solve that possibility)

 

Oh well. At least here's some code to get you started.

 

You are excused, as I hid that question in the very last sentence of my post. However, after a bit of pondering, I looked at the way the Earwigo builder handles multiple languages. And there I found this hidden gem:

 

WWB_localize_input = Wherigo.ZInput(cartPakkenTheParcel)
WWB_localize_input.InputType = "MultipleChoice"
WWB_localize_input.Choices = {"Dansk","English"}
WWB_localize_input.Text = "Sprog // Language?"
WWB_localize_input.WWB_cart = cartPakkenTheParcel

function WWB_localize_input:OnGetInput (input)
  WWB_localize_input_handler(self, input)
end

 

And then the WWB_localize_input_handler is free to poke at the innards of the input object:

 

function WWB_localize_input_handler (input_object, input_value)
  local i = 1
  while (i) do
     local l = input_object.Choices[i]
...

 

So I think I can achieve what I wanted to do by adding a table of Zones to my input object at definition time, and then picking the zone with the same index as the answer string for further processing, by using self.zoneTable. I've not yet tried it out, but with my present understanding of Lua, it should be possible to add.

 

And while we are at the subject, what is the upper limit on the number of MS choices the various players are able to handle? And for that matter, show on a single screen?

Link to comment
And while we are at the subject, what is the upper limit on the number of MS choices the various players are able to handle? And for that matter, show on a single screen?

If you build a clever little test cartridge that goes round a loop adding an extra choice each time until it crashes, and post it in the Earwigo group, then /a/ people with all the players will test it for you, and /b/ I will use the results to generate a warning in the Earwigo cartridge editor if the author gets close to the "minimum maximum" value.

 

By the way, it looks from the example that you pasted as if you're using "//" instead of "@@" as the language separator. This should work OK, but I'd be interested to hear of any bugs, in case some very old code has sneaked in there that assumes "@@". (I'm always interested in bugs, of course. :))

Edited by sTeamTraen
Link to comment
And while we are at the subject, what is the upper limit on the number of MS choices the various players are able to handle? And for that matter, show on a single screen?

If you build a clever little test cartridge that goes round a loop adding an extra choice each time until it crashes, and post it in the Earwigo group, then /a/ people with all the players will test it for you, and /b/ I will use the results to generate a warning in the Earwigo cartridge editor if the author gets close to the "minimum maximum" value.

 

I will do that.

 

By the way, it looks from the example that you pasted as if you're using "//" instead of "@@" as the language separator. This should work OK, but I'd be interested to hear of any bugs, in case some very old code has sneaked in there that assumes "@@". (I'm always interested in bugs, of course. :))

 

And the // is only used as separators in the parts where translation is not possible, which are the cartridge name, cartridge description and the question asking for the language to use. As I see it, those three strings are inherently impossible to localize without compiling seperate cartridges.

Link to comment

If you build a clever little test cartridge that goes round a loop adding an extra choice each time until it crashes, and post it in the Earwigo group, then /a/ people with all the players will test it for you, and /b/ I will use the results to generate a warning in the Earwigo cartridge editor if the author gets close to the "minimum maximum" value.

 

I have built a simple cartridge to test the possibilities. I have tried to run it in the WhereYouGo app for android, DesktopWIG and in the emulator. In all three cases, I could add more than 100 options, without any ill effects.

 

I'd like to hear how the Garmins and iPhone app handles this.

Link to comment
And the // is only used as separators in the parts where translation is not possible, which are the cartridge name, cartridge description and the question asking for the language to use. As I see it, those three strings are inherently impossible to localize without compiling seperate cartridges.

There's also the "Starting Location Description". I was hoping that you'd cut me some slack on the question asking which language to use; that kind of has to be multilingual. :)

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...