Jump to content

Photo

[weidu] how to quit script early

weidu

6 replies to this topic

#1 lynx

lynx
  • Modders
  • 3144 posts
  • Gender:Male
  • Location:Ljubljana, Slovenija

Posted 28 February 2015 - 03:14 PM

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. 


GemRB - IE anywhere.
Mages needed! Looking for Planescape: Torment testers
Play android version IS NOT SUPPORTED ANYMORE: reported bugs will be ignored! Still looking for builders ...


#2 Mike1072

Mike1072
  • Gibberling Poobah
  • 2534 posts
  • Gender:Male
  • Location:Canada

Posted 28 February 2015 - 04:06 PM

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



#3 CrevsDaak

CrevsDaak

    imma lil orc now duh duh

  • Modders
  • 166 posts
  • Gender:Male
  • Location:Bs. As., Argentina

Posted 28 February 2015 - 05:10 PM

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;
}


#4 lynx

lynx
  • Modders
  • 3144 posts
  • Gender:Male
  • Location:Ljubljana, Slovenija

Posted 01 March 2015 - 12:25 AM

FAIL will return an error, which may give the wrong impression. Still better than ifdefing everything, I guess. Thanks.


GemRB - IE anywhere.
Mages needed! Looking for Planescape: Torment testers
Play android version IS NOT SUPPORTED ANYMORE: reported bugs will be ignored! Still looking for builders ...


#5 Jarno Mikkola

Jarno Mikkola

    The Imp

  • Modders
  • 6829 posts
  • Gender:Male
  • Location:The town where the dead haven't keeled over, yet. In Finland.

Posted 01 March 2015 - 01:23 AM

Well, if you don't want to use the FAIL, but still wish to restart, then you should read this, as I asked it as well and it worked wonderfully.


Welcome to the sanity, you are free to search for the limit, it's out there, we drew it in the sand.
Here's how to install all the ... mods you ever really could want to Infinity Engine games. I removed the stable word from there as Roxanne began to add BS mods that are likely to break compatibility from the BWS.

#6 lynx

lynx
  • Modders
  • 3144 posts
  • Gender:Male
  • Location:Ljubljana, Slovenija

Posted 01 March 2015 - 02:12 PM

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.


GemRB - IE anywhere.
Mages needed! Looking for Planescape: Torment testers
Play android version IS NOT SUPPORTED ANYMORE: reported bugs will be ignored! Still looking for builders ...


#7 Wisp

Wisp
  • Modders
  • 1142 posts
  • Gender:Male

Posted 02 March 2015 - 10:31 AM

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.)


Edited by Wisp, 02 March 2015 - 10:39 AM.




Reply to this topic



  



1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users