Post new topic    
Metal Slime
Send private message
Plotscript help - if and else 
 PostWed Jul 03, 2013 9:40 pm
Send private message Reply with quote
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. Confused
This is the whole plotscript ...

Code:

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
Metal Slime
Send private message
 
 PostWed Jul 03, 2013 10:11 pm
Send private message Reply with quote
If/thens should be more like this:

Code:
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:
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.
FYS:AHS -- Swapping out some step-on NPCs for zones + each step script
Puckamon -- Not until the reserve party is expanded.[/size]
Liquid Metal King Slime
Send private message
 
 PostWed Jul 03, 2013 10:38 pm
Send private message Reply with quote
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:
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.
Metal King Slime
Send private message
Re: Plotscript help - if and else 
 PostThu Jul 04, 2013 4:35 am
Send private message Reply with quote
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:

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.
Metal Slime
Send private message
 
 PostFri Jul 05, 2013 1:25 pm
Send private message Reply with quote
Thanks a lot! Grin
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? :/
Slime Knight
Send private message
 
 PostSat Jul 06, 2013 8:48 pm
Send private message Reply with quote
marionline wrote:
Thanks a lot! Grin
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.
Display posts from previous: