Passing Parameter to Function

tbritton
17 Oct 2013, 01:55
I must be missing something here. I'm trying to pass a parameter to a function. In most cases I can get everything to work, but when trying to use the parameter (for example the number 2) to complete the name of an exit (for example north_exit_2) I can't get it to work. I have tried parens, quotes, etc. with no luck.

Here's the script that calls the function:

fbRoomDescription (Foggy Bottom 2, 2)


Here's the function. I want to replace all the exitVar with the number 2. So make exit invisible should be: north_exit_2.

if (rmVar.fog = 2) {
msg ("The narrow path winds through mesquite scrub, and continues to the east. The smell reminds you of a steak sizzling on a charcoal grill. To the north is a small creek, narrow enough in places you could almost jump over it. There's a steep, crumbly path up the side of the mountain.")
MakeExitInvisible (north_exit_+exitVar)
}
else if (rmVar.fog = 3) {
msg ("The narrow path winds through mesquite scrub, and continues to the east. The smell reminds you of a steak sizzling on a charcoal grill. To the north is a small creek, narrow enough in places you could almost jump over it. There's a steep, crumbly path up the side of the mountain.")
}
else {
msg ("You are surrounded by a dense fog. Distant sounds--the croaking of frogs, the whisper of trees in the wind--seem to come from every direction. Between the limited visibility and the way sound carries in the moisture-laden air, you feel slightly disoriented.")
if (GetBoolean(bronze_bell, "on")) {
msg ("You hear the sound of the church bell to the east.")
}
}


Thanks in advance for the help.

R2T1
17 Oct 2013, 02:41

MakeExitInvisible (north_exit_+exitVar)



I think this should be -
MakeExitInvisible ("north_exit_" + exitVar)

provided that exitvar is a string type and not an integer. If you need it to be an integer for the rest of your code, then you can convert it to a string before you concatenate it. (Check the ToString function.)

tbritton
17 Oct 2013, 18:08
Thanks for the response. Firstly you were correct I did have an integer/string problem. Added the ToString, verified it was being converted to a string, but still get the following error:

Error running script: Error compiling expression 'object': RootExpressionElement: Cannot convert type 'String' to expression result of 'Element'

exitVar = ToString (exitVar)
if (rmVar.fog = 2) {
msg ("The narrow path winds through mesquite scrub, and continues to the east. The smell reminds you of a steak sizzling on a charcoal grill. To the north is a small creek, narrow enough in places you could almost jump over it. There's a steep, crumbly path up the side of the mountain.")
MakeExitInvisible ("north_exit_" + exitVar)
}
else if (rmVar.fog = 3) {
msg ("The narrow path winds through mesquite scrub, and continues to the east. The smell reminds you of a steak sizzling on a charcoal grill. To the north is a small creek, narrow enough in places you could almost jump over it. There's a steep, crumbly path up the side of the mountain.")
}
else {
msg ("You are surrounded by a dense fog. Distant sounds--the croaking of frogs, the whisper of trees in the wind--seem to come from every direction. Between the limited visibility and the way sound carries in the moisture-laden air, you feel slightly disoriented.")
if (GetBoolean(bronze_bell, "on")) {
msg ("You hear the sound of the church bell to the east.")
}
}

jaynabonne
17 Oct 2013, 18:35
You probably want:

MakeExitInvisible (GetObject("north_exit_" + exitVar))

(If that doesn't work, you might need to break it into two lines:

exit = GetObject("north_exit_" + exitVar)
MakeExitInvisible(exit)


tbritton
17 Oct 2013, 18:47
First one worked perfect. Thanks jaynabonne.