Jump to content

[weidu] how to quit script early


lynx

Recommended Posts

Reading the docs, I see no mention of EXIT/RETURN or the like that I'm used from other languages. How do you do it?

 

I'm querying the user for input and for some values the mod just needs to print a message and exit gracefully, while for the rest the real work begins.

Link to comment

You just put variable check on everything after what you want to execute and only set that variable to one if you want to execute that. Also, WeiDU functions return by variable/name (like in Pascal) instead of by value (like in C).

FAIL can be used to terminate installation of a component with a message.

He wants something more like an early-return in C (I can't think of a simpler language to exemplify this):
int Function(int some_int)
{
        int x, y = 0;
        if (some_int == MAGIC_NUMBER)
                return 0; /* this automatically stops processing what is left in the funtion */
        else
        }
                x = some_int
                y = some_int / 2 << 4 & 7
                some_int = x * y + some_int
                        return some_int;
        {
}
or even more simple:
int func(void)
{
return 0; /* anything past this line is never executed to due the function returning a value here */
int c; c = 5738;
if (c == 3 || c == 5738)
  return 10;
}
Link to comment

it's not about restarting, but exiting. I'm already using a loop to sanity check the input, but this is unrelated. A take on CrevsDaak's suggestion (with an extra file to avoid useless indentation or checks) sounds the cleanest, but is still silly for a < 100 line mod.

Link to comment

I assume this comes up because you want to exit the script without SUCCESSFULLY INSTALLED as the end result? Aborting the installation with FAIL is currently the only way to do that. A component consisting of only IO that does not change game state (e.g., PRINT) can be successfully installed like any other. May I suggest you don't worry about it? (Delicate edit: what you are asking for is nonsense. TP2 is not a general-purpose scripting language.)

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...