Fun with Properties
steve the gaming guy
26 Nov 2007, 19:34I looked through a few threads on here and don't see any that address my particular problem. It seems simple but I can't get it to work no matter what I try.
I'm going to give my actual game example to get right to the point. I want the player to use an item in a room that makes the people get scared and run out.
So, I started by giving the crowds a property of scared, thinking that if an item with a property of weapon were used in the room whether on them directly or just used in general in the same room, they would panic and I would move the crowd objects out.
Maybe this will be similar to the drop all/take all scenario as far as running a script on every object in the room but should it also run a script on the item you are holding? [if item used has property of "weapon", then every item in the room with property of "scared" gets moved out]
Sounds simple in theory.
I'm going to give my actual game example to get right to the point. I want the player to use an item in a room that makes the people get scared and run out.
So, I started by giving the crowds a property of scared, thinking that if an item with a property of weapon were used in the room whether on them directly or just used in general in the same room, they would panic and I would move the crowd objects out.
Maybe this will be similar to the drop all/take all scenario as far as running a script on every object in the room but should it also run a script on the item you are holding? [if item used has property of "weapon", then every item in the room with property of "scared" gets moved out]
Sounds simple in theory.
I think Im Dead
26 Nov 2007, 20:06Okay this is just one or two steps more than what I responded with in the other, older thread. Code first, then explanation.
Code:
Explanation:
The logical place to start the check seems to be whenever you use an object. So when the command to use an object is entered we take flight. First checking, does this object have the weapon property? If not do what normally happens when using an object, if it DOES let's see if there are npc's around and if they are scared move 'em.
So we go through each object in the current room and see if they have a property NPC, if they don't Quest just forgets them, if they do Quest is going to hold onto them for a second(it calls them #quest.thing# automatically) and check them for another property SCARED, if they have this property then they get moved to NEW-ROOM otherwise they stay put.
Pretty simple huh? Now you could have gotten the same effect with less code by not checking if you gave those NPC objects a property called NPC and instead just checking each object in the room for the SCARED property and moving them accordingly. However if you accidentally gave a chair a SCARED property it would hightail it out of there, and this way if somebody in the room is rough and tough and not scared they will stay there.
Basically I just threw in the extra step because I have coding OCD and like to keep everything exact.
Edit: To make everything just as you said, the property to check for wou
Hope that helps.
Code:
command <use #@object#> {
if property <#object#; weapon> then {
for each object in <#quest.currentroom#> if property <#quest.thing#;npc> then {
if property <#quest.thing#;scared> then move <#quest.thing#;new-room>
}
}
else msg <You use your object or whatever would normally happen.>
}
Explanation:
The logical place to start the check seems to be whenever you use an object. So when the command to use an object is entered we take flight. First checking, does this object have the weapon property? If not do what normally happens when using an object, if it DOES let's see if there are npc's around and if they are scared move 'em.
So we go through each object in the current room and see if they have a property NPC, if they don't Quest just forgets them, if they do Quest is going to hold onto them for a second(it calls them #quest.thing# automatically) and check them for another property SCARED, if they have this property then they get moved to NEW-ROOM otherwise they stay put.
Pretty simple huh? Now you could have gotten the same effect with less code by not checking if you gave those NPC objects a property called NPC and instead just checking each object in the room for the SCARED property and moving them accordingly. However if you accidentally gave a chair a SCARED property it would hightail it out of there, and this way if somebody in the room is rough and tough and not scared they will stay there.
Basically I just threw in the extra step because I have coding OCD and like to keep everything exact.
Edit: To make everything just as you said, the property to check for wou
Hope that helps.
steve the gaming guy
26 Nov 2007, 21:16Very cool! Thank you!
I used this variation and it does what I need:
The only thing is if there are multiple items in the room and it returns "The crowd panics in fear and runs for their lives!" for every crowd in the room.
I also tried a variation where the command is <use #@object# on #@quest.thing#> and could not get it to work.
I used this variation and it does what I need:
command <use #@object#> if property <#object#; weapon> then {
for each object in <#quest.currentroom#> if property <#quest.thing#; scared> then {
msg <The crowd panics in fear and runs for their lives!>
move <#quest.thing#; inven>
}
}
else msg <You use your object or whatever would normally happen.>
command <use #@object# on #@quest.thing#> if property <#object#; weapon> then {
if property <#quest.thing#; scared> then {
msg <The crowd panics in fear and runs for their lives!>
move <#quest.thing#; inven>
}
}
else msg <You use your object or whatever would normally happen.>
The only thing is if there are multiple items in the room and it returns "The crowd panics in fear and runs for their lives!" for every crowd in the room.
I also tried a variation where the command is <use #@object# on #@quest.thing#> and could not get it to work.
Elexxorine
26 Nov 2007, 21:34flag off <msg>
for each object in <#quest.currentroom#> {
if property <#quest.thing#; scared> then {
if not flag <msg> then {
msg <The crowd panics in fear and runs for their lives!>
move <#quest.thing#; inven>
flag on <msg>
} } }
This kind of thing I use a lot, you can use a variable instead if you want.steve the gaming guy
26 Nov 2007, 21:40Ok, so that is still addressing all objects in the room. What if I want to alternatively use it on one object at a time?
Let's say I have a crowd, a man and a woman. [3 NPCs]
Instead of "use gun" making them all leave, I would "use gun on man" and make him leave and the other 2 [crowd/woman] stays in the room. The in a 2nd command, I want to make the rest of the room scatter so I simply "use gun" making the remaining NPCs leave.
Get it?
Let's say I have a crowd, a man and a woman. [3 NPCs]
Instead of "use gun" making them all leave, I would "use gun on man" and make him leave and the other 2 [crowd/woman] stays in the room. The in a 2nd command, I want to make the rest of the room scatter so I simply "use gun" making the remaining NPCs leave.
Get it?
Elexxorine
26 Nov 2007, 21:49The bold lines are all I've actually changed, just insert them in the same fashion with the other code.flag off <msg>
for each object in <#quest.currentroom#> {
if property <#quest.thing#; scared> then {
if not flag <msg> then {
msg <The crowd panics in fear and runs for their lives!>
move <#quest.thing#; inven>
flag on <msg>
} } }
command <use #@object#>{
flag off <msg>
if property <#object#; weapon> then {
for each object in <#quest.currentroom#> if property <#quest.thing#; scared> then {
if not flag <msg> then {
msg <The crowd panics in fear and runs for their lives!>
move <#quest.thing#; inven>
flag on <msg>
} }
else msg <You use your object or whatever would normally happen.>
}
command <use #@object# on #@quest.thing#> {
flag off <msg>
if property <#object#; weapon> then {
if property <#quest.thing#; scared> then {
msg <The crowd panics in fear and runs for their lives!>
move <#quest.thing#; inven>
flag on <msg>
} }
else msg <You use your object or whatever would normally happen.>
}
There you go!steve the gaming guy
28 Nov 2007, 17:33This still fits under the heading of "fun with properties"...
There is a section in the Manual that says this:
This does work. I tried it using a gun with a property of weapon=1. So it returns. "The gun has a rating of 1". Beautiful.
I tried to incorporate it with a man where if you use an item with a rating of 1 (greater than 0), he will beg for mercy. I want to make another man where if you use an item with a rating of 2 or so, he will beg for mercy, ELSE he will laugh at you for threatening him with such a weenie weapon.
Anyway, that's the goal I'm trying to get to. I am still trying to make the first part work (rating of 1).
With the above code, it only returns "He laughs at you".
quest.thing does not seem to work. What is the better way to write this?
There is a section in the Manual that says this:
Ye Mighty Manual wrote:#object name:property#
For example, if you have an object called "cod" and it has a "smellstrength" property, you could read this in an msg command using:
msg <The cod has a smell strength rating of #cod:smellstrength#.>
This does work. I tried it using a gun with a property of weapon=1. So it returns. "The gun has a rating of 1". Beautiful.
I tried to incorporate it with a man where if you use an item with a rating of 1 (greater than 0), he will beg for mercy. I want to make another man where if you use an item with a rating of 2 or so, he will beg for mercy, ELSE he will laugh at you for threatening him with such a weenie weapon.
Anyway, that's the goal I'm trying to get to. I am still trying to make the first part work (rating of 1).
define object <man>
look <The man eyes you menacingly.>
speak <He doesn't want to talk.>
prefix <the>
use anything if ( #quest.thing:weapon# > 0 ) then {
msg <He begs for mercy!>
}
else msg <He laughs at you>
end define
With the above code, it only returns "He laughs at you".
quest.thing does not seem to work. What is the better way to write this?
Alex
28 Nov 2007, 17:54It should be:
use anything if ( #(quest.thing):weapon# > 0 ) then ...
steve the gaming guy
28 Nov 2007, 18:14Oh, a message from the master. Dang, I got excited there for a second. I thought it was going to work. Maybe it would help if I also put the define of one of the weapons.
and I have now fixed the man object using your alteration:
For some reason, this still gives me "He laughs at you"
define object <small gun>
alt <gun>
look <This weapon wouldn't hurt a fly. Well that's not true. It would kill it. Let's say this gun wouldn't hurt a dungeon troll unless it was at point blank.>
take <You take the gun and feel happy.>
speak <Hi gun, how are you?>
prefix <the>
displaytype <little weapon>
article <it>
gender <it>
properties <weapon=1>
end define
and I have now fixed the man object using your alteration:
define object <man>
look <The man eyes you menacingly.>
speak <He doesn't want to talk.>
prefix <the>
use anything if ( #(quest.thing):weapon# > 0 ) then msg <He begs for mercy!>
else msg <He laughs at you>
end define
For some reason, this still gives me "He laughs at you"
Elexxorine
28 Nov 2007, 20:53Yeah. If the name of the object is a variable it has to have brackets around it in the property string function.
#object:property#
#(variable):property#
steve the gaming guy
28 Nov 2007, 21:28I know. I'm saying that didn't work.
paul_one
28 Nov 2007, 21:41what happens if you change it to:
?
If that produces the weapon's name then I'll be very surprised.
use anything msg <#quest.thing#>
?
If that produces the weapon's name then I'll be very surprised.
Elexxorine
29 Nov 2007, 10:02It's not working because #quest.thing# is for 'for each object in' scripts, not 'use' scripts. Use #quest.use.object.name#. Man that took finding in the documentation, it's not listed under built-in string variables, but if you look under the basic object stuff, use section it says it. Try it with that string instead, it should work.
steve the gaming guy
29 Nov 2007, 19:30Oh ok, that makes sense and I just learned about the #quest.use.object.name# a couple days ago. I'll have to play with that. Thanks!
paul_one
30 Nov 2007, 06:17Also guys, don't forget about the $thisobject$ function, which I think only works inside actions and stuff.
This produces the local object name - so you can put it into types and stuff without worrying what the object is that's running that code.
But yeah - the use's should have that variable in it (which is noted in the same area in the documentation - but indeed not built-in variables).
This produces the local object name - so you can put it into types and stuff without worrying what the object is that's running that code.
But yeah - the use's should have that variable in it (which is noted in the same area in the documentation - but indeed not built-in variables).
steve the gaming guy
04 Dec 2007, 06:04elexxorine wrote:It's not working because #quest.thing# is for 'for each object in' scripts, not 'use' scripts. Use #quest.use.object.name#. Man that took finding in the documentation, it's not listed under built-in string variables, but if you look under the basic object stuff, use section it says it. Try it with that string instead, it should work.
Thanks! It's taken a few days to actually get back to this problem. Just wanted to let you know that it worked with the #quest.use.object.name#. I really could have used that a long time ago for other projects!!

Elexxorine
04 Dec 2007, 08:23Glad I could help at least now.