Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

Spells or Else

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
RedMaverickZero
Three pointed, red disaster!
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 12 Jul 2003
Posts: 1459

PostPosted: Sat May 06, 2006 11:07 am    Post subject: Spells or Else Reply with quote

I'm trying to make a script which looks to see if the player has a certain spell, if not they check for the next hero, if none of them have it, then it goes to the else command. However, when I tested this script, it showed the else command when some of the heroes (1/3 or 2/3) had the spell. And the (show text box(167)) only showed up when all three heroes knew the spell. If I could get some help on how to get this to work, I'd be very appreciative.

script, candylesson,begin
suspend player
(
if(knows spell (hero:Mark,atk:Fireball)) then, (show text box (167))

if(knows spell (hero:Stephen, atk:Fireball)) then, (show text box (167))

if(knows spell (hero:Todd, atk:Fireball)) then, (show text box (167))

else (show text box (164))
)

resume player
end
Back to top
View user's profile Send private message Send e-mail AIM Address
Mr B




Joined: 20 Mar 2003
Posts: 382

PostPosted: Sat May 06, 2006 11:57 am    Post subject: Reply with quote

The "else" is logically attached ONLY to the immediately preceding "if" statement.

So what I expect is happening is that text 164 is shown whenever Todd doesn't know Fireball. Is that right?

Hmm...there are a couple of ways around this.

The hack way would be to always show textbox 164 at the beginning of the script. Since textboxes are only truly displayed at the next "wait" statement, it will be immediately replaced by textbox 167 if any of the heroes knows Fireball. Problem: if textbox 164 does anything besides showing text (starts a script, calls another textbox, etc.), this method will fail, probably spectacularly.

A slightly preferable method would be to have a bunch of nested "if-else" statements -- since it only matters that one of the heroes knows the spell (it doesn't matter which hero), you could get away with this.

Personally, I would create a variable that holds the number of the textbox to be shown. I would give it the default value of 164, then change it if any of the heroes knows Fireball. After all of the logical tests, I would use "show textbox()" and pass it that variable.

It would look something like this:
Code:

variable(tb)
tb := 164

if(knows spell (hero:Mark,atk:Fireball)) then, (tb := 167)

if(knows spell (hero:Stephen, atk:Fireball)) then, (tb := 167)

if(knows spell (hero:Todd, atk:Fireball)) then, (tb := 167)

show textbox(tb)


You could condense the three "if" statements into one if you use a couple of "or" commands, but that really doesn't improve legibility -- and I doubt this is a process-critical bit of code!

Good luck.
Back to top
View user's profile Send private message
Iblis
Ghost Cat




Joined: 26 May 2003
Posts: 1233
Location: Your brain

PostPosted: Sat May 06, 2006 11:59 am    Post subject: Reply with quote

You could just reorganize it like this, all into one if statement.

Code:
script, candylesson,begin
suspend player

if(knows spell (hero:Mark,atk:Fireball) ,or, knows spell (hero:Stephen, atk:Fireball) ,or, knows spell (hero:Todd, atk:Fireball)) then
(show text box (167))
else (show text box (164))


resume player
end


EDIT: Mr. B's variable way is probably best.
_________________
Locked
OHR Piano
Back to top
View user's profile Send private message Send e-mail
RedMaverickZero
Three pointed, red disaster!
Halloween 2006 Creativity Winner
Halloween 2006 Creativity Winner



Joined: 12 Jul 2003
Posts: 1459

PostPosted: Sat May 06, 2006 12:14 pm    Post subject: Reply with quote

Thanks a lot you guys. Even though I used Iblis', I still learned a thing or two from Mr.B's. You guys will be referenced in my readme file for helping me out.
Back to top
View user's profile Send private message Send e-mail AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group