Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

seeking affirmation? look no further than the

Validator Contraption:

Works much like a field, but will display informative (or annoying) text below if the value doesn't pass muster.

The validation rule(s) are provided in the script of the contraption instance, by filling out the "on check" function. This function is given the current text, and may return either an error message (a string) or the number 0 if the text is valid. In the above example, the validation function looks like so:


%%WGT0{"w":[{"name":"validator1","type":"contraption","size":[128,41],"pos":[173,242],"def":"validator","widgets":{"v":{},"e":{}}}],"d":{"validator":{"name":"validator","size":[128,41],"resizable":1,"margin":[89,5,6,22],"description":"a text input field with configurable validation rules.","script":"on is_valid  x do 0~me.event[\"check\" x] end\non get_valid   do is_valid[v.text] end\non get_text    do if is_valid[v.text] v.text else 0 end end\non set_text  x do if is_valid[x] v.text:x end end\n\non change x silent do\n err:card.event[\"check\" v.text]\n e.text:if 0~err\n  if !silent card.event[\"change\" x] end\n  \"\"\n else\n  err\n end\nend\n\non view do\n v.font  :card.font\n v.locked:card.locked\n v.show  :card.show\n e.show  :card.show\n change[v.text 1]\nend","template":"on change x do\n \nend\n\non check x do\n \nend","attributes":{"name":["text"],"label":["Text"],"type":["string"]},"widgets":{"v":{"type":"field","size":[120,17],"pos":[4,4]},"e":{"type":"field","size":[120,14],"pos":[4,23],"locked":1,"border":0,"style":"plain"}}}}}

I'm super new to Decker and trying to use the validator contraption as a way to implement a specific password in order to be able to advance to the next card. I'm not sure if that is the intended function of this contraption or a possibility and would greatly appreciate any guidance.

It would probably be just as easy to use a plain field as a Validator for what you describe. Say you have a field named "myfield". You could then have a button with a script something like:

on click do
 if myfield.text ~ "the password"
  go[someOtherCard]
 end
end

Or perhaps you could give the field a script and enable a button when it contains the correct text?

on change val do
 myButton.locked: !val~"the password"
end

This thread has some additional discussion about implementing a password/search system that might be useful.

(+1)

Thanks for the quick feedback! I shall try to implement both of those solutions, if only to get a better grasp on the system and figure out which one works best. I will also check out the linked thread. Thanks again!