Plotscrip-if+else-again

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Plotscrip-if+else-again

Post by marionline »

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. :???:
The mesaage was "expced top-level-declaration, but found "else" as message.

Code: Select all

# 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.
User avatar
BMR
Metal King Slime
Posts: 3310
Joined: Mon Feb 27, 2012 2:46 pm
Location: The Philippines
Contact:

Post by BMR »

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
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

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 ... ting_Tools
Last edited by TMC on Mon Jul 22, 2013 11:22 am, edited 1 time in total.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Thanks for your answers, BMR and TMC, :)

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 :( , still it's fast to use than the OHR's compiler.

And that's what the script lookes like now:

Code: Select all

# 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
User avatar
msw188
Metal Slime
Posts: 783
Joined: Tue Oct 16, 2007 1:43 am
Location: Los Angeles, CA

Post by msw188 »

Doesn't "else" require its own parentheses? So you need

Code: Select all

else
  (
  #stuff
  )
instead of

Code: Select all

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.
Last edited by msw188 on Mon Jul 22, 2013 2:24 pm, edited 2 times in total.
I am Srime
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Code: Select all

	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: Select all

	else if (checktag (tag:run)) then 

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

Code: Select all

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
)
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Thanks for you help! :D

I'll use the example as a basis for other scripts and I'll hopefully remember that else needs ( and ). :)
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Come to think of it why don't I just make "else, if" equivalent to "else if"?
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Image
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: Select all

# 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
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6247
Joined: Mon Dec 08, 2008 7:07 am
Location: Home
Contact:

Post by Spoonweaver »

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: Select all

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.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

@Soonweaver: Yes, it WAS the problem. I didn't realize the checktag was missing...
Thanks, you saved the game! :D
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7460
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

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.
Post Reply