Why does this not work?

tyilo

Member
when i run the code it will always popup and i have to answer. Why does it ignore the first if?
Code:
if(my_fullness() == 0 && my_inebriety() == 0)
{
  void main(boolean normal)
  {
    if(normal == true)
    {
      cli_execute("eat 5 peach pie");
      cli_execute("drink 9 shot of peach schnapps");
      cli_execute("drink 1 fine wine");
    }
  }
}
 

tebee

Member
I think cos it's going to the main() as the start of the code to execute. - not sure if there's a way around that though.


Tom
 

holatuwol

Developer
I didn't even think that was a valid script. o_0

I think there's a boolean confirm(string promptMessage) that does what you're trying to do, though.
 

tyilo

Member
It is a valid script! It will popup with a box (like that you could choose which message icon you would use in this forum) where you could choose between true and false.

And it didn't work with confirm!
 

Veracity

Developer
Staff member
I think he meant that perhaps it shouldn't be a valid script. Yes, you can define functions inside scopes (blocks surrounded by {}) - but they should only be accessible from within that scope. But, we apparently treat main() differently, since it is calling main() from top-level even though the only main() in the file is in an inner scope.

I think I'm going to put in a check and issue an error message if main() is not at top level. That will "solve" your issue, in that your script will fail validation, rather than misleading you into thinking that it COULD work.

holatuwol told you about the confirm(). When you say "it didn't work with confirm", I assume you understand that when you put in confirm(), you also REMOVE the argument to main(), right?
 

Veracity

Developer
Staff member
[quote author=Veracity link=topic=1626.msg7630#msg7630 date=1205848958]
I think I'm going to put in a check and issue an error message if main() is not at top level. That will "solve" your issue, in that your script will fail validation, rather than misleading you into thinking that it COULD work.[/quote]
I have done exactly that.
 
Top