Log In  


Hey all, I managed to hack together a (sort of) storylet system today.

Here's a super pared-down example of how my storylet tables look right now:

goldcheck = {
 text="wow you sure have a lot of gold!",
 failtext="wow you sure are poor",
 condition = function() return gold > 50 end
}

But I would PREFER to have something like this:

goldcheck = {
 text="wow you sure have a lot of gold!",
 failtext="wow you sure are poor",
 condition = gold > 50
}

In the first one I can find out if the condition returns true using 'if goldcheck:condition()' but I feel like having to type all those functions annd returns and ends is going to bloat the token count pretty quickly and it's not too nice to look at.

But the problem with the comndition NOT being explicitly defined as a function is, as I'm sure you've guessed, that 'gold > 50' gets evaluated once when the table is created then 'goldcheck.condition' always returns true no matter what the 'gold' variable changes to.

Is there any way to achieve what I want?



There is, and you've already outlined it in the first snippet. If you want an alternate method, you could put the condition in a string, then do res = load("return " .. cond)() to run the string as code and return the result.


Ooh that's amazing! Thank you! I was wondering if I could use a string but I was thinking if the method existed it would be called "eval" like in javascript.

EDIT: I don't think the pico-8 'load' function works like that



[Please log in to post a comment]