Plotscript help - if and else

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

Plotscript help - if and else

Post by marionline »

Good evening,
I need help to find the mistakes in this ploscrit, the messages I recives while runing hamsterspeak/the editor were a bit confusing. Maybe I'm doing something fundamentally wrong with if-else-clauses. I don't know, so I ask for help. :???:
This is the whole plotscript ...

Code: Select all

include, plotscr.hsd
include, FoolsQuest.hsi
# Here all the scripts go, that are used in the game FooldQuest (against the All-Seeing-Eye)
# ~marionline

#Tutorial
# run by NPCs to check what they say.
#checks the follwing tags
#4,tag:have bag
#5,tag:have coat
#6,tag:have bottle
#7,tag:have Kerli
#15,tag:Donowell in team

plotscript, bag, begin
if  (checktag (4) == 1) then, 
	show text box (11) # Great! Now, let's get the red bottle. It's a potion, use it to recover HP.
else then
	show text box (15) # That's not the thing I'm looking for right now...
end # end of plotscript

plotscript, coat, begin
if  (checktag (4) == 1) then, 
	show text box (15) # That's not the thing I'm looking for right now...
else if (checktag (5) == 1)
	show text box (15) # That's not the thing I'm looking for right now...
else then 
	show text box (15) # That's not the thing I'm looking for right now...
end # end of plotscript

plotscript, bottle, begin
if  (checktag (6) == 1) then, begin

	show text box (12) # Eh? Where is my marionette?
end
else if (check tag (4) == 1)
	begin
	show text box (15) # That's not the thing I'm looking for right now...
	end #end if the else-clause
else if (check tag (5) == 1)
	begin
	show text box (15) # That's not the thing I'm looking for right now...
	end #end if the else-clause
else then 
	begin
	show text box (15) # That's not the thing I'm looking for right now...
	end #end the else-clause
end # end of plotscript

plotscript, bird,begin
else if (check tag (7) == 1)
	begin
	show text box (13) #fight bird
if  (checktag check tag (6) == 1) then,
	beginn
	show text box (15) # That's not the thing I'm looking for right now...
	end # of the if-clause
else if ( check tag (4) == 1)
	begin
	show text box (15) # That's not the thing I'm looking for right now...
	end #end if the else-clause
else if ( check tag (5) == 1)
	begin
	show text box (15) # That's not the thing I'm looking for right now...
	end #end if the else-clause
else then 
	begin
	show text box (15) # That's not the thing I'm looking for right now...
	end #end the else-clause
end # end of plotscript

plotscript, NPC Kobold, begin
# if Do-no-Well is team leader:
if  (checktag check tag (15) == 1) then,
begin
	show text box (86) 
end #end if the if-clause
end # end of plotscript
Last edited by marionline on Wed Jul 03, 2013 9:41 pm, edited 1 time in total.
User avatar
FnrrfYgmSchnish
Metal Slime
Posts: 721
Joined: Thu Jun 18, 2009 4:37 am
Location: Middle of Nowhere, VA

Post by FnrrfYgmSchnish »

If/thens should be more like this:

Code: Select all

if(check tag(tag:InsertTagNameHere) == off)
		then(
				#do stuff
		)
		else(
				#do different stuff
		)
Every if, then, or else needs a ( immediately after it, and a ) at the end of everything inside that if/then/else command (so each separate if/then/else branch is surrounded by its own set of parentheses.)

If you have another if/then/else inside of a then or else, those need their own set of parentheses too, like these:

Code: Select all

if(check tag(tag:InsertTagNameHere) == off)
		then(
				#do stuff
		)
		else(
				if(check tag(tag:OtherTagName) == off)
						then(
								#do different stuff
						)
		)
EDIT: Removed extra unnecessary )'s that I put in by accident... whoops.
Last edited by FnrrfYgmSchnish on Wed Jul 03, 2013 10:14 pm, edited 1 time in total.
FYS:AHS -- Swapping out some step-on NPCs for zones + each step script
Puckamon -- Not until the reserve party is expanded.[/size]
User avatar
Spoonweaver
Liquid Metal King Slime
Posts: 6247
Joined: Mon Dec 08, 2008 7:07 am
Location: Home
Contact:

Post by Spoonweaver »

Actually, using begin and end instead of ( and ) is fine to do in plotscripting.

However, I see a couple problems with your flow commands.

Code: Select all

else then
I'm not sure this is correct

Also, you need a couple more ends in places it seems.



You might want to try using FnrrfYgmSchnish's method. Using begin and end can become confusing at times.
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Re: Plotscript help - if and else

Post by TMC »

You can actually combine 'else' and 'if' into 'else if', but there's no such keyword as 'else then'. Aside from that, you are missing lots of begins and ends, or equivalently, ('s and )'s. Each 'then' and each 'else' must be followed either by ( or by ", begin". (If the begin is on a different line, then the comma is optional. Otherwise you need to use a command to separate keywords like 'then' and 'begin'.) Here's the corrected version of your 'coat' script:

Code: Select all

plotscript, coat, begin
  if  (checktag (tag:have bag)) then (
    show text box (15) # That's not the thing I'm looking for right now...
  ) else if (checktag (tag:have coat)) then (
    show text box (15) # That's not the thing I'm looking for right now...
  ) else (
    show text box (15) # That's not the thing I'm looking for right now...
  )
end
Also, notice that it's easier to use constants like "tag:have bag" directly instead of the ID numbers.
Last edited by TMC on Thu Jul 04, 2013 4:39 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 a lot! :D
I corrected the script with yiur help and expainations, and now I can continue working on my game's scripts and plot.

I just realised that I can not set tag by using an NPC (only by using Textboxes) ... so the whole scripts are rather useless. >_<
So, I'll have to think of other ways to mange the whole textbox-reaction- things neatly then...
Do you have any ideas? :/
Last edited by marionline on Fri Jul 05, 2013 1:57 pm, edited 1 time in total.
User avatar
crowtongue
Slime Knight
Posts: 115
Joined: Mon Feb 25, 2013 4:57 pm

Post by crowtongue »

marionline wrote:Thanks a lot! :D
I corrected the script with yiur help and expainations, and now I can continue working on my game's scripts and plot.

I just realised that I can not set tag by using an NPC (only by using Textboxes) ... so the whole scripts are rather useless. >_<
So, I'll have to think of other ways to mange the whole textbox-reaction- things neatly then...
Do you have any ideas? :/
While you can't set a tag by using an NPC in CUSTOM, just create a simple script and change the Run Script option in Edit NPC.
Post Reply