If, And, Then, Or, Else?

Make games! Discuss those games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
Master K
King Slime
Posts: 1899
Joined: Sat Jun 11, 2011 9:40 pm
Location: A windswept rock in the Atlantic Ocean

If, And, Then, Or, Else?

Post by Master K »

I really do hate tag checking and flow control.
I need help with some scripts...

Code: Select all

plotscript, which gender, begin
	if (check tag(6 == ON)) then
	$2 = "he"
	$3 = "him"
	$4 = "He"

        else
        
	$2 = "she"
	$3 = "her"
	$4 = "She"
	
	end
	
It says that else needs to be follow an If or Then.

Also, I want to make a script that sets a heroes picture differently when they step into a certain area based on a tag check, and then turn it off when they're not in a certain area. How can I do that?
User avatar
RMSephy
Metal Slime
Posts: 356
Joined: Mon Dec 21, 2009 5:56 pm

Post by RMSephy »

then and else won't work if you just leave them hanging like that. The proper syntax should be like this:

Code: Select all

plotscript, which gender, begin
   if (check tag(6 == ON)) then, begin
     $2 = "he"
     $3 = "him"
     $4 = "He"
   end

   else, begin
     $2 = "she"
     $3 = "her"
     $4 = "She"
   end
   
end 
You can do the latter using zones and an "Each step" script. On each step, check to see if the player's standing in a certain zone (read zone). If he is, then change his walkabout sprite.
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

People keep on mistaking what the syntax of if statements is. I really wonder why. Have you read the Plotscripting Tutorial? Looked at any other articles about scripting on the wiki?

HSpeak also ought to be made better at describing what the error is.

Sephy missed another mistake: "if (check tag(6 == ON))" should be "if (check tag(6) == ON)", which is actually the same as "if (check tag(6))". That one's also very popular, but I blame it on common sense.

Also, you can use ( and ) instead of begin and end. I think it leads to cleaner code:

Code: Select all

plotscript, which gender, begin
   if (check tag(6)) then (
     $2 = "he"
     $3 = "him"
     $4 = "He"
   ) else (
     $2 = "she"
     $3 = "her"
     $4 = "She"
   )
end 
Finally, whether or not you want to use a tag or zones ("read zone (id)" returns true or false) to figure out if the player is in the area , you probably wanted to know what command to use. Like this:

Code: Select all

plotscript, update walkabout, begin
  if (check tag ([TAG ID[)) then (   # or read zone ([ZONE ID]), as required
    set walkabout picture (find hero ([HERO ID]), [SPRITE SET ID], outside battle)
    set walkabout palette (find hero ([HERO ID]), [PALETTE ID], outside battle)  # if needed
  ) else (
    # Or use 'set hero picture/palette' instead
    reset walkabout picture (find hero ([HERO ID]), outside battle)
    reset walkabout palette (find hero ([HERO ID]), outside battle)  # if needed
  )
end
Last edited by TMC on Sat Feb 11, 2012 1:02 am, edited 1 time in total.
User avatar
Master K
King Slime
Posts: 1899
Joined: Sat Jun 11, 2011 9:40 pm
Location: A windswept rock in the Atlantic Ocean

Post by Master K »

Thank you, but by tag check...I mean't one determining which picture to set the hero to. The hero can either be a guy or a girl.

EDIT:

Code: Select all

plotscript, grass animation, begin 
  if (read zone(1)) then (   # or read zone ([ZONE ID]), as required 
    set hero picture (0, 11, outside battle) 
  ) else ( 
    # Or use 'set hero picture/palette' instead 
    reset hero picture (find hero (0), outside battle) 
  ) 
end
I tested this script for the male hero, and it does not work.
Last edited by Master K on Sat Feb 11, 2012 4:37 pm, edited 1 time in total.
User avatar
RMSephy
Metal Slime
Posts: 356
Joined: Mon Dec 21, 2009 5:56 pm

Post by RMSephy »

The syntax for read zone is actually 'read zone (zone id, x, y)'. Try something like 'read zone(1, herox, heroy)'
TMC
Metal King Slime
Posts: 4101
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Opps.

Also, "set hero picture (0, 11, outside battle) " should be "set hero picture (find hero(0), 11, outside battle)" although it'll appear to work if hero 0 is in the first party slot.
Post Reply