Returning a string function's value

xordevoreaux
In the game template I'm making, I have made a copy of the LOOKAT command, and in part of the command, instead of having the usual boring "Nothing out of the ordinary." if the game creator doesn't add a description to an object, I make a call to a function that returns a random string.

if (LengthOf(lookdesc) = 0) {
lookdesc = wt_NothingOutOfTheOrdinary
}

That's not working. This is the error:

look at candle
Error running script: Error compiling expression 'wt_NothingOutOfTheOrdinary': Unknown object or variable 'wt_NothingOutOfTheOrdinary'

This is the function:

<function name="wt_NothingOutOfTheOrdinary" type="string">
choice = GetRandomInt(1,10)
switch (choice) {
case (1) {
return (Looks fairly nondescript how matter how you look at it.)
}
case (2) {
return (Ordinary. Very ordinary.)
}
case (3) {
return (Under different circumstances, it might be out of the ordinary, but not today.)
}
case (4) {
return (Hm. Could appear beautiful, could appear monstrous, all depends on your mood, possibly.)
}
case (5) {
return (Without a doubt, this is very, very, ordinary.)
}
case (6) {
return (Possibly the most ordinary thing you'll see all day.)
}
case (7) {
return (Ordinarily, this might look ordinary, but we're not sure. Probably is.)
}
case (8) {
return (Without a doubt, this is ordinary.)
}
case (9) {
return (Yep. Ordinary.)
}
case (10) {
return (Don't stare at it too long, it won't get any less ordinary.)
}
}
</function>

HegemonKhan
I think you need to use an Attribute, not a Variable:

Attribute: Object_name.lookdesc = wt_NothingOutOfTheOrdinary
~VS~
Variable: lookdesc = wt_NothingOutOfTheOrdinary

as it doesn't know: okay, do 'lookdesc', but.... OF WHAT ?????

'this' is a special usage that Gets the Object that is the Parent of the 'lookdesc' Script

if (LengthOf (this.lookdesc) = 0) {
this.lookdesc = wt_NothingOutOfTheOrdinary
}


-------------

otherwise, you may need to have your Return strings be inside double quotes:

return ("xxxxxxxxxxxxxxxxx.")

------------

lastly, maybe your CASES' numbers may need to be inside double quotes:

case ("1") {
}
case ("2") {

xordevoreaux
On the default LOOKAT command, the LookDesc variable has no qualifier. It's just a variable local to the script.

I've experimented some more, and it happens if I try to use a PRINT command with an expression using the function on the event after entering a room, so it's not particular to the LOOKAT function, I'm thinking.

Edit:
The case numbers were created via the GUI, I do very little hand-coding.

HegemonKhan
I edited in a bit more possible fixes to my previous post, I hope one will work, laughs.

xordevoreaux
I get the same problem if a create a local variable on a script and set it to:

<function name="testfunction" type="int">
return (3)
</function>

where I set it to be used on a given room's enter script:

<enter type="script">
mytestvariable = testfunction
</enter>

xordevoreaux
Figured it out.
It was a combination of needing to put the return values in "" as well as typing () after this parameterless function name.
I had originally put the () after the function name, but with the double quotes missing, still had the error.
Now that I did both fixes at once, it's working.
Thanks.

HegemonKhan
ah, very good job!, I forgot that Functions need to have the ' (blank or with Parameters) ' at the end, as I usually have Parameters, regardless of whether it has Parameters or not.

for example, creating a new (empty) stringlist:

game.my_stringlist = NewStringList ()

and *then*, adding in the items:

list add (game.my_stringlist, "item1")
list add (game.my_stringlist, "item2")

The Pixie
It is confusing because when they are on a line all on their own you do not need the parenthesis. So this is okay:
ClearScreen

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums