Skip to content

List expressions #1

Description

@FlamerShaftglutton

Issue:

Right now a script can have multiple expressions, allowing you to script multiple actions in sequence, separated by semicolons. The FEOIR function allows for multiple arguments, all of which will be executed in sequence.

However, since the If function must have exactly 2 or 3 arguments (if <condition> <execute on true> [<execute on false>] ) there is no way to allow an arbitrary number of Expressions to be evaluated in either of the conditional branches.

Workarounds:

An arbitrary number of functions can be evaluated by using the + function. If the first argument is a string (even just "") then it will be treated as a concatenation command. This will evaluate each expression in the order provided, convert the return values to strings, then return the concatenation of all the strings. This adds a bit of extra overhead, but doesn't require much extra typing. A trivial example would be:
(if (< (get player.hitpoints) 10) (+ "" (set player.hitpoints 100) (set 0 1)));
This would check if the player has dropped below 10 hitpoints, and if they did then reset them to 100 and set register 0 to value 1.

Suggested Solution

Adding "list" as a value type would allow passing lists to functions, including the If function. It would also allow for lists to be passed back and forth between other functions. At this point that wouldn't be that useful, but it would allow for easier creation of future flow-control improvement, such as proper loops. Since this would be helpful but not required it was not put into the original Scripting coding, but would make a nice addition in the future.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions