$getobjectname doesn't appear to work

MerryCo
07 Dec 2006, 15:11
The following will return ! if objectname is in the same room or the player's inventory.

$getobjectname(#object#; #quest.currentroom#; inventory)$

According to the help file, it defaults to looking in the same room, or the player's inventory. However, the following also returns !

$getobjectname(#object#)$

According to the help file, you can set it to search gamewide. The following will return the object name I'm looking for:

$getobjectname(#object#; game)$

But I want to restrict the scope to only the current player's room and inventory. Is there a workaround? By the way, I've tried this on both 3.x and 4.x beta, with the same results.

MaDbRiT
07 Dec 2006, 15:51
Hi Merry

You must be getting something wrong syntax wise, $getobjectname()$ works exactly like it is supposed to.. try running this code...


' "Game Name"
' Created with QDK Pro 4.0 Beta 2

define game <Game Name>
asl-version <391>
gametype singleplayer
start <Start Room>
game author <Your Name>
game version <1.0>
game copyright <© 2006 ...>
game info <Enter any additional information about this game here.>
command <find anywhere #obj#> {
msg <$getobjectname(#obj#; game)$>
}
command <find #obj#> {
msg <$getobjectname(#obj#)$>
}

end define

define options
debug on
panes on
end define

define room <Start Room>
look <Description Goes Here>

define object <blue_widget>
alias <widget>
look <it is a blue widget>
take
displaytype <Object>
article <it>
gender <it>
end define

end define

define room <limbo>

define object <gun>
alias <revolver>
look <Smith & Wesson.38>
end define

end define

define text <intro>
Enter intro text here
end define

define text <win>
Enter win text here
end define

define text <lose>
Enter lose text here
end define



You'll see that "find widget" returns the proper name of the widget be it in the room or in the inventory as it is supposed to do, but "find revolver" returns ! as the revolver is in another room.

'Find anywhere revolver' will return 'gun' (this code is using the 'game' parameter)

Obvious thought - you do realise that this function is purely used to get real object names for objects that have aliases?

Al

MerryCo
07 Dec 2006, 15:59
Thanks for taking the time to reply!

Here's my code, and it always returns a !

command <!objname #object#> {
msg <|n[GC] Object name is: |b$getobjectname(#objectname#)$|xb.>

MaDbRiT
07 Dec 2006, 16:04
Hi Merry


command <!objname #object#> {
msg <|n[GC] Object name is: |b$getobjectname(#objectname#)$|xb.>
}



The ony thing I can think of is that you aren't passing the correct variable to your function. If you set the variable #object# in your command, you must pass #object# and not #objectname# to the function!

Al

MerryCo
07 Dec 2006, 16:09
If I'm reading the help file correctly, $getobjectname(#object#)$ returns the actual name of the object, if the alias is passed to it in #object#. So, let's say I have the following object:


define object <LIB:STDOBJECTS:CUTLASS>
alias <cutlass>
look <It's a rather sharp cutlass.>
prefix <a>
displaytype <Object>
article <it>
gender <it>
end define


$getobjectname(cutlass)$ should return LIB:STDOBJECTS:CUTLASS, should it not?

MaDbRiT
07 Dec 2006, 16:19
Hi Merry

Yup - exactly so, you pass the alias to get back the real name - and it DOES work. :D

In your posting @3:59 p.m. your code is wrong, you get the alias of an object from the player and store it in #object# but then pass an entirely different thing (the content of variable #objectname# which is quite probably nothing) to the function.

i.e. you used


command <!objname #object#> {
msg <|n[GC] Object name is: |b$getobjectname(#objectname#)$|xb.>
}


when I'm sure you MEANT something like


command <!objname #object#> {
msg <|n[GC] Object name is: |b$getobjectname(#object#)$|xb.>
}



Hope this helps.

Al

MerryCo
07 Dec 2006, 16:26
My fault. I should have posted the entire code, instead of copying and pasting snippets. Here was my original code:


command <!objname #object#> {
msg <|n[GC] Object name is: |b$getobjectname(#object#)$|xb.>
}


And when that didn't work (and it still doesn't on my end), and to throw in some error-checking I tried:


command <!objname #object#> {
set string <objectname; $getobjectname(#object#)$>
if #objectname# = ! then {
msg <|n[GC] Error: Can't find |b#object#|xb! Object must be in the same room or in your inventory.>
}
else {
msg <|n[GC] Object name is: |b#objectname#|xb.>
}
}


Which also does not work. I tried this in 4.x beta and 3.x with the same result.

MaDbRiT
07 Dec 2006, 16:36
Hi Merry

Try this...


command <!objname #object#> {
set string <objectname; $getobjectname(#object#)$>
if (#objectname#=!) then {
msg <|n[GC] Error: Can't find |b#object#|xb! Object must be in the same room or in your inventory.>
}
else {
msg <|n[GC] Object name is: |b#objectname#|xb.>
}
}


Al

Alex
07 Dec 2006, 16:37
Rather than going to all of that effort manually checking the object name yourself, why not just set up your command like this:


command <!objname #@object#> {
msg <|n[GC] Object name is: #object#$|xb.>
}

MerryCo
07 Dec 2006, 16:44
Alex,

That worked, thanks!

MaDbRiT
07 Dec 2006, 16:49
Merry

The auto de-aliasing method that Alex suggests above is the official way to do this sort of thing now - BUT it does have limits.

If you need to get the real name of an object NOT in the current location and NOT in the inventory - then it won't work.

Just a little 'gotcha' - because I'm sure we mentioned using the 'game' parameter of $getobjectname()$ earlier in this thread.

Al