If...Then...Else statement in a custom command
mandmwest
21 Dec 2003, 21:13Hello Eveyone
I am at this point just testing some script, trying various things and am have trouble acomplishing what I want with custom commands.
The objective is to (as simply as possible) set up a custom command, in this case strike/hit/punch that will repond with 3 different messages determined by -
1. There is no such object in the room.
2. The object is in the room but has no specific strike command
3. The object is in the room and has a specific strike command.
The first two option are scripted in the game defintion block while the third is in the room definition block.
In my test room there are two objects - a ball and a pillow.
What I want to happen when it is run is...
1. hit lamp - there is no lamp so the reply is "don't be absurd"
2. hit pillow - it is in the room but has no specific command so you get the reply "you swing wildly and miss"
3. hit ball - it is in the room and has a specific command that replys.
What actually happens is that number 2 and 3 work fine but if the object is not in the room I get the games default message for this.
Now I know that I could use the default and even customize it but what if I what different messages for -
hit the <non-exsistant object>
jump on <non-exsistant object>
swim in <non-exsistant object>
Here is my script The command thats not working is at the end of the game define block. I've tried several different way - two are still here.
Sorry this is so long but I do have one other question about this. As you can see the ball has alt names of beach ball and plastic ball. that means that you can type examine ball/beach ball/plastic ball, any of these work.
But if you try to do the same with strike it only works with the actual name. Doalt names and prefixes only work with built in commands and not custom commands.
Thanks for any help and everyone have a great holiday
I am at this point just testing some script, trying various things and am have trouble acomplishing what I want with custom commands.
The objective is to (as simply as possible) set up a custom command, in this case strike/hit/punch that will repond with 3 different messages determined by -
1. There is no such object in the room.
2. The object is in the room but has no specific strike command
3. The object is in the room and has a specific strike command.
The first two option are scripted in the game defintion block while the third is in the room definition block.
In my test room there are two objects - a ball and a pillow.
What I want to happen when it is run is...
1. hit lamp - there is no lamp so the reply is "don't be absurd"
2. hit pillow - it is in the room but has no specific command so you get the reply "you swing wildly and miss"
3. hit ball - it is in the room and has a specific command that replys.
What actually happens is that number 2 and 3 work fine but if the object is not in the room I get the games default message for this.
Now I know that I could use the default and even customize it but what if I what different messages for -
hit the <non-exsistant object>
jump on <non-exsistant object>
swim in <non-exsistant object>
Here is my script The command thats not working is at the end of the game define block. I've tried several different way - two are still here.
' "Kimemma"
' Created with QDK 3.5 - UNREGISTERED VERSION
!include <q3ext.qlb>
define game <Kimemma>
asl-version <350>
gametype singleplayer
start <Test Room 1>
game author <Mike West>
game info <Created with QDK 3.5 - UNREGISTERED EVALUATION VERSION.>
'====== the follow two line will not work ========================================================
'command <strike #@whatever#> if not here <#whatever#> then msg <Don't be absurd!> else msg <You swing wildly and miss.>
command <strike #@whatever#> if here <#whatever#> then msg <You swing wildly and miss.> else msg <Don't be absurd!>
'=================================================================================================
end define
define synonyms
hit; punch = strike
beach ball; pastic ball = ball
end define
define room <Test Room 1>
alias <lab>
prefix <the>
command <strike ball> msg <the ball flys through the air, bounces off the wall and hits you in the head... good one.>
define object <ball>
alt <plastic ball; beach ball>
look <It is an ordinary big round plastic beach ball just sitting there minding it's own business.>
take
speak <The ball just sits there silently.>
examine <Upon closer examination you find that some prankster has taped a note to the ball that says "hit me".>
prefix <a>
article <it>
gender <it>
end define
define object <pillow>
alt <blue; flat; flat pillow; blue pillow; flat blue pillow>
look <It is a flat blue pillow.>
take
examine <There is nothing out of the ordinary with this pillow.>
prefix <a>
article <it>
gender <it>
end define
end define
define text <intro>
end define
define text <win>
end define
define text <lose>
end defineSorry this is so long but I do have one other question about this. As you can see the ball has alt names of beach ball and plastic ball. that means that you can type examine ball/beach ball/plastic ball, any of these work.
But if you try to do the same with strike it only works with the actual name. Doalt names and prefixes only work with built in commands and not custom commands.
Thanks for any help and everyone have a great holiday
I think Im Dead
22 Dec 2003, 00:34I tested this out and it all works but the "Don't be absurd" part(even the hit 'beach ball', etc.). The problem with how you want to do this is you can't define a response for a specific object that doesn't exist. You said what if you wanted to have a different response for jump on, swim in, blahblah 'non-existant object'. Taking both of these situations into mind and trying to figure out a way to solve the problem I've come up with this.
I'm a fan of object properties so I just gave the ball a property called 'strike' with a value of 'The ball flies through the air, bounces off the wall and hits you in the head... good one.', this way you don't have to create an extra command specifically for the ball. The strike command will read the strike property from whatever object it is used in conjunction with, if it doesn't have one, 'You swing wildly and miss!' if the object isn't there, 'Don't be absurd!'. You could copy this command and modify it a bit to suit whatever custom command you need(for the most part). It's not the way I'd do it ideally, but it works well. Hope it's of use.
command <strike #whatever#> {
set numeric <nullcheck; $lengthof(#@whatever#)$>
if ( %nullcheck% <> 0 ) then {
if property <#@whatever#; strike> then msg <$objectproperty(#@whatever#; strike)$> else msg <You swing wildly and miss!>
}
else msg <Don't be absurd!>
}
I'm a fan of object properties so I just gave the ball a property called 'strike' with a value of 'The ball flies through the air, bounces off the wall and hits you in the head... good one.', this way you don't have to create an extra command specifically for the ball. The strike command will read the strike property from whatever object it is used in conjunction with, if it doesn't have one, 'You swing wildly and miss!' if the object isn't there, 'Don't be absurd!'. You could copy this command and modify it a bit to suit whatever custom command you need(for the most part). It's not the way I'd do it ideally, but it works well. Hope it's of use.
mandmwest
22 Dec 2003, 02:44Thanks ITID, that does work. After Reading your response I have two more questions. you said
Considering I've read your coding examples in posts throughout this form and only hope to understand asl half as well someday, how would you do it?
I ask because this is not just for one stupid ball and pillow. What I am actually trying to do is create generic custom commands for an extensive (25, 50, 100???) list of action words to be used globally throughout the game. Then if I actually want to use the custom command (like strike) on a particular object in a particular room (like the ball) I would define it locally which would over ride the generic response.
Does anyone have a better way to do this other than what I tried which isn't working or ITID's way whish is.
Question two is just stupid. How did I manage to make this thread two wide to view without scrolling? None of the other threads are.
Thanks
It's not the way I'd do it ideally, but it works
Considering I've read your coding examples in posts throughout this form and only hope to understand asl half as well someday, how would you do it?
I ask because this is not just for one stupid ball and pillow. What I am actually trying to do is create generic custom commands for an extensive (25, 50, 100???) list of action words to be used globally throughout the game. Then if I actually want to use the custom command (like strike) on a particular object in a particular room (like the ball) I would define it locally which would over ride the generic response.
Does anyone have a better way to do this other than what I tried which isn't working or ITID's way whish is.
Question two is just stupid. How did I manage to make this thread two wide to view without scrolling? None of the other threads are.
Thanks
paul_one
22 Dec 2003, 07:59I'd personally have it do an object action - and have any messages/whatever in the object action....
Dunno how ITID would do it though... Kepp up the good work ITID
.
Dunno how ITID would do it though... Kepp up the good work ITID
I think Im Dead
22 Dec 2003, 15:23Yeah, see, that'd probably be a better way of doing things. That way you can have the script do whatever(which is still possible my way, but requires all kinds of witchcraft and trickery)instead of just printing a message.
I just got into the habit of using properties because of QuestNet being all nitpicky and it being easier to just type properties <whatever-I-need; oh-this-too> instead of indenting and adding an action.
P.S. Oh man my balls hurt! Anyone else get that at all?
I just got into the habit of using properties because of QuestNet being all nitpicky and it being easier to just type properties <whatever-I-need; oh-this-too> instead of indenting and adding an action.
P.S. Oh man my balls hurt! Anyone else get that at all?
paul_one
23 Dec 2003, 08:27*kicks ITID in the balls*
Does that make the pain better/worse?
*kicks again*
.... Nobody here will know what he's on about..... PHEW!
Does that make the pain better/worse?
*kicks again*
.... Nobody here will know what he's on about..... PHEW!
kingmorgoth99
08 Jan 2004, 21:23i know this has probobly aready been said but take out the @'s in the <#@whatever#>
P.S.
hi guys im back i haven't posted cos my computer CRAASHED down to the deepest pits of hell so i had to wipe it completely snd after that the net screwwed up but finnaly i fixed it and im back
P.S.
hi guys im back i haven't posted cos my computer CRAASHED down to the deepest pits of hell so i had to wipe it completely snd after that the net screwwed up but finnaly i fixed it and im back
paul_one
09 Jan 2004, 07:50Actually, that should work just fine - what he could have done was have "strike #@object#" so he didn't need to type out all those @'s all the time, but you shoud leave the @'s in incase the alias is different from the object name!