The Dink Network

Dynamically generated choices

December 17th, 02:41 AM
duck.gif
toof
Peasant He/Him
I disagree. 
So uhh, I'm trying to generate a dynamic choice menu. Surprisingly, the script below somewhat works
  int &crap = 0;
  choice_start();
    set_y 200
    set_title_color 15
    title_start();
    Dynamic choice
    title_end();
    loop:
    if(&crap < 3)
    {
      "Option &crap"
      &crap += 1;
      goto loop;
    }
  choice_end();
  say("I've picked &result", 1);


The only problem is that choice menu is never shown, and last choice is always picked up somehow (number 2 in this case). I've attached this to talk script. At first I've attached it to hit(), and thought pressing CTRL is what messes things up. Apparently not.

Has anyone tried to do this, and can it be done?
December 17th, 11:52 AM
death.gif
Seseler
Peasant He/Him Heard Island And Mcdonald Islands
 
What exactly you mean by dynamic?

If you just want that some choices are not shown you can just add conditionals to the choices, but you presumably knew that.

If you want to make a large number of "option N" choices then you do have to manually unroll your choice list AFAIK

If you want to let player pick an arbitrary number either do a looping choice menu with "current value: &crap" title, with options "[increase/decrease] by [1/10/...]"; or do whatever Ultimate Cheat does with its variable editor.
December 17th, 12:48 PM
duck.gif
Toof
Peasant He/Him
I disagree. 
Dynamic as it can generate a number of choices, based on a current value of a variable, as demonstrated in the snippet above. I will check the file to see what was done there, cause I am facing issues.
December 17th, 01:08 PM
death.gif
Seseler
Peasant He/Him Heard Island And Mcdonald Islands
 
You should be able to do something like this
int &crap = 3
choice_start()
  set_y 200
  set_title_color 15
  title_start()
  Dynamic choice
  title_end()
(&crap >= 1) "Choice 1"
(&crap >= 2) "Choice 2"
(&crap >= 3) "Choice 3"
(&crap >= 4) "Choice 4"
(&crap >= 5) "Choice 5"
choice_end()
say("I've picked &result", 1)
December 17th, 02:41 PM
duck.gif
Toof
Peasant He/Him
I disagree. 
That's not (fully) dynamic. Choices are hardcoded, and I don't know what values &crap might have. It might be 20 or more, at which point such approach becomes unmanagable.

So, generate choices in a "while/for" loop from 0 to N
December 17th, 05:53 PM
spike.gif
I wonder if there's a low-ish limit for how many choices you can have, in which case having spaceholders for each wouldn't really decrease the dynamism.

The choice menu gets separated into pages after about 13 lines IIRC, which while not a hard limit is kind of awkward.
December 17th, 06:03 PM
duck.gif
toof
Peasant He/Him
I disagree. 
With all due respect scratcher, I was looking for a specific solution, not a shift to a problem I totally forgot about

Dang... I'll might have to limit the number of choices and do stuff manually up to 10, while "sacrificing" what I originally had in mind. Luckily, that's something I can live with and may even be beneficial overall.

I'll keep the topic open for suggestions to the original problem, just in case someone knows if this is doable, or where the problem of "autoselect" is.
December 17th, 09:28 PM
wizardg.gif
You're only providing choices to the player when &crap is < 3 but &crap becomes 3 very fast.

What happens if you move 'option &crap' up so it's not within the if check?
December 17th, 09:44 PM
peasantmb.gif
yeoldetoast
Peasant They/Them Australia
Oh, NOW YOU'VE DONE IT! 
It's an attempt to programmatically add options to a choice menu which isn't possible in DinkC due to the line parser changing completely once it hits menu options (edit: my reply looks nonsensical since lep changed his post). It's fairly straightforward in DinkLua however:

function talk()
    -- Store references
    local refs = {"beans", "pasta", "salad", "rice"}
    local mymenu = dink.create_choice_menu()
    -- Add random foods to it
    for i = 1, 20 do
      local randint = math.random(1, #refs)
      mymenu:add_choice(refs[randint])
    end

    local mychoice = mymenu  how()
    player  ay("I chose option " .. global.result)
end
December 17th, 10:18 PM
wizardg.gif
Yeah I edited my post because as I was looking back through my response I realized I had understood it incorrectly.
December 18th, 05:28 AM
duck.gif
toof
Peasant He/Him
I disagree. 
@LeprochaUn - moving "option &crap" out of the if() behaves the same way. Menu is never rendered and last choice is selected somehow.

@yeolde - thanks. I'll have to check how to proceed from here.

December 18th, 10:44 AM
peasantmb.gif
yeoldetoast
Peasant They/Them Australia
Oh, NOW YOU'VE DONE IT! 
Depending on how badly you want it, it would be possible to implement Seseler's approach above combined with my approach to writing DinkC, i.e. autogenerating it with a more capable programming language, in this case to account for all possible permutations. It's also possible to chain (AND) conditionals, seemingly as many times as you like to determine their addition to the option list.
December 18th, 01:19 PM
duck.gif
toof
Peasant He/Him
I disagree. 
@yeoldetoast I badly want a better language than DinkC in certain scenarios, but I could use others to generate this particular script... It's just... crazy... Nevermind. I'm continuing to develop with what I have. Combined with what scratcher said, it makes sense to include some limitations.
December 19th, 12:24 AM
custom_robj.png
Robj
Jester He/Him Australia
You feed the madness, and it feeds on you. 
Write a script that re-created the entire choice menu from scratch, so you have unlimited control over its functionality.