Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Questions on the "enum" contraption

A topic by LavaRamen created Apr 05, 2024 Views: 167 Replies: 4
Viewing posts 1 to 2

Hi! Been playing around with Decker for a while but the first time to make a post and ask for help

I've been trying to code up a semi-generator, and the [enum] contraption is nearly exactly what im looking for! But my question is, is it possible to have another button randomise and choose one option on an enum on click?  And how would that translate in code?

In the Generator that I have, and from my reference Koboldy Go! , the generators work a [button click]-[field]randomize from [grid values]; 

Is it possible with the enum contraption to have a [button click]-[enum field] randomize from [enum options] & [field] update as enum choose option? That way players can still interact with the enum and change the chosen option if they like.

Dunno if the question makes any sense, thanks for anyone that might help out in advance :) !

Developer(+1)

If you have an enum contraption named "enum1" and a button intended for randomizing it, you could give the button a script something like the following:

on click do
 enum1.value:random["\n" split enum1.options]
end

reading the "options" attribute of an enum contraption returns a newline-delimited string of options which can be cracked into a list of options with "split". Given a list, the random[] function will pick a random element, and the enum contraption also permits having its value written via the "value" attribute (automatically constraining writes to within the valid set of options).

If you're doing this sort of thing in many places, you could modify the enum prototype to expose a method for randomizing it, adding a function something like the following to the prototype script:

on get_randomize do
 on randomize do
  set_value[random["\n" split get_options[]]]
 end
end

And then simplify the button script above to

on click do
 enum1.randomize[]
end

Make sense?

This helps so much! thank you! it works, but not...quite!

I tried the solution given, and (splitting the options) it did work! but for some reason *reading* the chosen random has problems?

Here's what I got:

  • A button that goes
on click do
    generate[]
    enum1.value:random["\n" split enum1.options]
end
  • enum1, with a bunch of options, and 
  • A field, called teste1
  • Another field, called StoryFin
  • And the Card script that goes
on generate do
    teste1.text:enum1.value
    StoryFin .text:  teste1.text, "-continued with a lot of other text and stuff"
end

But what's happening on the button click:

Enum1 picks a random option just fine, but DIFFERENT from teste1 and StoryFin. teste1 and stdryfin has the Same text, but always different from enum1

Modifying the prototype also don't quite work. I don't know how to fix this so I'm reaching out again >< hope this isn't a stupid question! The og answer is already such a big help

Developer (1 edit)

in your "on click..." script, you're calling generate[] before you choose a new random value for enum1.

(+1)

ahh thank you!