Post new topic    
Metal Slime
Send private message
Plotscrip-if+else-again 
 PostMon Jul 22, 2013 10:31 am
Send private message Reply with quote
Hello,
I need some help again.
Hamserspeak.exe is not happy with this script anymore, after I added an other script behind it one.

I tried to find the mistakes, changes a few ( and )... well, now I am as confused again. Confused
The mesaage was "expced top-level-declaration, but found "else" as message.

Code:

# is triggered by textbox 23
# checks if player shall buy dye and has not beein in trouble yet.
if (checktag (tag:buy dye) && checktag(tag:was in trouble))  then
   (
      show textbox (113) # should continue with 131
      set tag (tag: buy dye, off)
      set tag (41,on)
      wait for textbox
      show textbox (131) # should continue with the script
      wait for textbox
   )
   else
      if (checktag (tag:run)) then
      (
      show textbox (187)
      )
   )
   else
      if (checktag (tag:confess)) then 
      (
      (show textbox (242)
      )
   )
end


By the way, is there an Editor for writing Plotscripts?
Like Notepad++ or such?
I'd like to see several Errors/Misstakes as once. These Compiler(?)-Messages from Hamsterspeak are rather confusing me.
Metal King Slime
Send private message
 
 PostMon Jul 22, 2013 10:53 am
Send private message Reply with quote
You can't have two elses like that I believe. That, and they're missing their parenthesis.

As for an IDE, Notepad++ works fine. Or you can use Gedit, it's what I use to write and to compile.
Being from the third world, I reserve the right to speak in the third person.

Using Editor version wip 20170527 gfx_sdl+fb music_sdl
Metal King Slime
Send private message
 
 PostMon Jul 22, 2013 11:22 am
Send private message Reply with quote
If you want to use the "else if" construct, then 'else' and 'if' must be next to each other on the same line. Assuming that that's what you want, you also have an extra ) before the last else.

There are two dedicated HamsterSpeak editors that are in a usable state: HssEd, and HamsterWhisper.
http://rpg.hamsterrepublic.com/ohrrpgce/Plotscripting_Tools
Metal Slime
Send private message
 
 PostMon Jul 22, 2013 12:21 pm
Send private message Reply with quote
Thanks for your answers, BMR and TMC, Smile

Now i have new questions: Is it possible to use several else ifs - one afer another- on the same level? Like switch-case?
Can I use case for checking tags or is this comand just for numbers?

I tried the Hamser Wisper, but the compiler also alsways shows just one mistake. And there is also no colored text Sad , still it's fast to use than the OHR's compiler.

And that's what the script lookes like now:
Code:
# is triggered by textbox 23
# checks if player shall buy dye and has not beein in trouble yet.
if (checktag (tag:buy dye) && checktag(tag:was in trouble))  then
   (
      show textbox (113) # should continue with 131
      set tag (tag: buy dye, off)
      set tag (41,on)
      wait for textbox
      show textbox (131) # should continue with the script
      wait for textbox
   )
   else
      if (checktag (tag:run)) then
      (
      show textbox (187)
      )
   else
      if (checktag (tag:confess)) then 
      (
      (show textbox (242)
      )
   )
end
Metal Slime
Send private message
 
 PostMon Jul 22, 2013 2:21 pm
Send private message Reply with quote
Doesn't "else" require its own parentheses? So you need
Code:
else
  (
  #stuff
  )

instead of
Code:
else
  #stuff


EDIT: If you want switch-case behavior, why not just use the switch-case commands? That's what it looks like from your if-else branching.

RE-EDIT: Never mind, I now see the issue is that you have lots of different tags to consider.
I am Srime
Liquid Metal King Slime
Send private message
 
 PostMon Jul 22, 2013 2:21 pm
Send private message Reply with quote
Code:

   else
      if (checktag (tag:run)) then

This will not work. "else if" is a single command, so you cannot break it into two lines. Write it like this instead:

Code:

   else if (checktag (tag:run)) then



Here is a generic example of a complex if/elseif/else block

Code:

if(condition) then(
  # do something
)else if(another condition) then(
  # do something else
)else if(another condition) then(
  # do something else
)else if(another condition) then(
  # do something else
)else if(another condition) then(
  # do something else
)else(
  # if none of the other conditions are true do this
)
Metal Slime
Send private message
 
 PostMon Jul 22, 2013 7:31 pm
Send private message Reply with quote
Thanks for you help! Grin

I'll use the example as a basis for other scripts and I'll hopefully remember that else needs ( and ). Smile
Metal King Slime
Send private message
 
 PostTue Jul 23, 2013 8:29 am
Send private message Reply with quote
Come to think of it why don't I just make "else, if" equivalent to "else if"?
Metal Slime
Send private message
 
 PostTue Jul 23, 2013 9:51 am
Send private message Reply with quote

Is that normal that the Complier says this?
The Tag "buy dye" is set then using another NPC, so it should be able to be set...
Then I get the message Hspeak.exe sreported failure.
Seems like something is still wrong here ... I guess I need some more help, please? ^^"

Script:
Code:

# is triggered by textbox 23
# checks if player shall buy dye and has not beein in trouble yet.
if (checktag (tag:buy dye) ==1  && checktag (41) ==off)  then
   (
      show textbox (113) # should continue with 131
      set tag (tag: buy dye, off)
      set tag (41,on)
      wait for textbox
      show textbox (131) # should continue with the script
      wait for textbox
   )
   else if (checktag (tag:run)) then
      (
      show textbox (187)
      )
   else if (checktag (tag:confess)) then 
      (
      show textbox (242)
      )
   else if  ((tag:buy dye) == off ) then 
      (
      show textbox (23)
      )
   else
      (
       show textbox (251)
      )
end
Liquid Metal King Slime
Send private message
 
 PostTue Jul 23, 2013 11:29 am
Send private message Reply with quote
i think there might be a problem with how you're trying to write it.
I suggest you use this format when doing what you're doing.
Code:
else if ( check tag (tag) == false ) then

It might not HAVE to be that way, but I'm fairly certain it will work if it is that way.
Metal Slime
Send private message
 
 PostTue Jul 23, 2013 2:13 pm
Send private message Reply with quote
@Soonweaver: Yes, it WAS the problem. I didn't realize the checktag was missing...
Thanks, you saved the game! Grin
Liquid Metal King Slime
Send private message
 
 PostTue Jul 23, 2013 2:15 pm
Send private message Reply with quote
TMC wrote:
Come to think of it why don't I just make "else, if" equivalent to "else if"?


Because multiple ways to do the same thing are confusing! Especially when the only benefit would be to hide a typo.

But a compile-time warning for else,if would be useful.
Display posts from previous: