Open Challenge: 'it' functionality

Overcat
19 Jan 2007, 17:49
I type "s". I receive the message:

"You cannot go that way. The door is closed."

I type "open it". I receive the message:

"I don't know what 'it' you're referring to."

This happens because I never actually referenced the door object yet. The first message, however, clearly indicates that a door is there, and so using 'it' in a responsive command would be natural. My attempts to manually set quest.lastobject have failed.

Anyone got a way to do this?

I think Im Dead
19 Jan 2007, 17:55
I'm pretty sure Quest used to do this, though not as vague as you are suggesting. It was more like...

>go to door

The door is locked you can't go through it.

>unlock it

You unlock the door.

Pulling the feature off through code would require in your case a custom travel command for each compass direction interacting with exit direction properties the room would have, where as trying to south would interact (and fail) with the south exit property then redirect a common IT variable to the door object blocking the path.

It wouldn't be that difficult at all really for normal commands to have an after-turn script that parses #quest.input# or whatever the last command variable it is, find the space in the input and saves the last word to be referenced as it until changed. Though with travel you would most likely be forced to turn your directions/doors/caves/whatever into either actual objects or a series of room properties.

Overcat
19 Jan 2007, 17:58

I'm pretty sure Quest used to do this, though not as vague as you are suggesting. It was more like...

>go to door

The door is locked you can't go through it.

>unlock it

You unlock the door.



Yeah, that still works. My problem is that I don't reference the door, I just try to go south.

Pulling the feature off through code would require in your case a custom travel command for each compass direction interacting with exit direction properties the room would have, where as trying to south would interact abd fail with the south exit property then redirect a common IT variable to the door object blocking the path.



Kind of what I already have set up. Except that the directional commands interact with exit objects, not properties. I cannot, however, seem to set the quest.lastobject string variable.

I think Im Dead
19 Jan 2007, 18:01
In typical fashion I wouldn't rely on Quest's built in ability to use IT, instead create something alone the lines of a before-turn script that will test an input variable, unlock #whatever#, to see if the #whatever# = IT and if so sub your own personal last interacted object variable.

Overcat
19 Jan 2007, 18:06
I also have

set string <quest.lastobject; #Game_LastObject#>


in the beforeturn script.

When the door object is checked to see if it's open via the command 'command <s>', I have

set string <Game_LastObject; #Self#>


This is in the OnFailedUse action of the door object. #Self# is a variable I set for every object at the beginning of actions with

set string <Self; $thisobject$>


Just because it's easier to reference #Self#.

For some reason, manually setting quest.lastobject at other times doesn't work, so in the beforeturn script I set it to equal a variable that I have already set. In this case, #Game_LastObject#. Even then, using the word 'it' in a command fails.

I think Im Dead
19 Jan 2007, 19:31
Oh man that was exciting. I hurriedly threw this together thinking you and I were both racing towards the same solution.

The trick was that Quest only identifies an object as the #quest.lastobject# variable once the object has been defined using the input #@variable# to identify the actual game object a player was referring to as an alias. So the trick is to identify objects without the @ modifier for variables, which is easy enough.

Here's my sloppy code to show that it works, referring to the objects as IT. Realistically, you could re-use all of the same variables in the Before/After turn scripts, I just gave each it's own set for clarity. It also displays a bit ugly, but I'll probably go ahead and pretty things up later.

The open challenge was awesome fun, and if you think of any other challenges post them.



' "IT-Game"

define game <IT-Game>
asl-version <400>
gametype singleplayer
start <IT-Room>
game author <TheRizzle>
game info <A sample/tutorial example on implementing the use of IT to refer to the last used object.>
beforeturn {
if ( $lengthof(#quest.command#)$ > 0 ) then {
set numeric <quest.SubIT-LocateStart; $instr(#quest.command#;_;)$>
set numeric <quest.SubIT-LocateEnd; $lengthof(#quest.command#)$>
set numeric <quest.SubIT-Math; %quest.SubIT-LocateEnd% - %quest.SubIT-LocateStart%>
set string <quest.SubIT-Parse; $right(#quest.command#; %quest.SubIT-Math%)$>
set string <quest.SubIT-Format; $left(#quest.command#; %quest.SubIT-LocateStart%)$>
if ( #quest.SubIT-Parse# = it ) then exec <#quest.SubIT-Format# #quest.FindIT-Parse#> else msg <no>
}
}
afterturn {
set numeric <quest.FindIT-LocateStart; $instr(#quest.command#;_;)$>
set numeric <quest.FindIT-LocateEnd; $lengthof(#quest.command#)$>
set numeric <quest.FindIT-Math; %quest.FindIT-LocateEnd% - %quest.FindIT-LocateStart%>
set string <quest.FindIT-Parse; $right(#quest.command#;%quest.FindIT-Math%)$>
msg <It = #quest.FindIT-Parse#>
}
command <push #object#> {
for each object in <#quest.currentroom#> if ( $objectproperty(#quest.thing#; alias)$ = #object# ) then msg <$objectproperty(#quest.thing#; push)$>
}
command <punch #object#> {
for each object in <#quest.currentroom#> if ( $objectproperty(#quest.thing#; alias)$ = #object# ) then msg <$objectproperty(#quest.thing#; punch)$>
}
end define

define options
debug on
panes disabled
end define

define room <IT-Room>

define object <obj001>
alias <ball>
look <You see a blue ball.>
prefix <a blue>
displaytype <Object>
article <it>
gender <it>
properties <push=You push the ball.; punch=You punch the ball.>
end define

define object <obj002>
alias <dog>
look <You see a brown dog.>
prefix <a brown>
displaytype <Object>
article <it>
gender <it>
properties <push=You push the dog.; punch=You punch the dog.>
end define

end define


Overcat
19 Jan 2007, 20:29

Oh man that was exciting. I hurriedly threw this together thinking you and I were both racing towards the same solution.



I think we were.

The open challenge was awesome fun, and if you think of any other challenges post them.



Sure, I think it's fun too. And if you've got any, lemme' know. I'm actively coding a game right now, so problems are bound to crop up. I'll be sure to post them before I figure them out.

But. The fun ain't over with this one. Look how I changed your code:

' "IT-Game" 

define game <IT-Game>
asl-version <400>
gametype singleplayer
start <IT-Room>
game author <TheRizzle>
game info <A sample/tutorial example on implementing the use of IT to refer to the last used object.>
beforeturn {
if ( $lengthof(#quest.command#)$ > 0 ) then {
set numeric <quest.SubIT-LocateStart; $instr(#quest.command#;_;)$>
set numeric <quest.SubIT-LocateEnd; $lengthof(#quest.command#)$>
set numeric <quest.SubIT-Math; %quest.SubIT-LocateEnd% - %quest.SubIT-LocateStart%>
set string <quest.SubIT-Parse; $right(#quest.command#; %quest.SubIT-Math%)$>
set string <quest.SubIT-Format; $left(#quest.command#; %quest.SubIT-LocateStart%)$>
if ( #quest.SubIT-Parse# = it ) then exec <#quest.SubIT-Format# #quest.FindIT-Parse#> else msg <no>
}
}
afterturn {
set numeric <quest.FindIT-LocateStart; $instr(#quest.command#;_;)$>
set numeric <quest.FindIT-LocateEnd; $lengthof(#quest.command#)$>
set numeric <quest.FindIT-Math; %quest.FindIT-LocateEnd% - %quest.FindIT-LocateStart%>
set string <quest.FindIT-Parse; $right(#quest.command#;%quest.FindIT-Math%)$>
msg <It = #quest.FindIT-Parse#>
}
command <push #object#> {
for each object in <#quest.currentroom#> if ( $objectproperty(#quest.thing#; alias)$ = #object# ) then msg <$objectproperty(#quest.thing#; push)$>
}
command <punch #object#> {
for each object in <#quest.currentroom#> if ( $objectproperty(#quest.thing#; alias)$ = #object# ) then msg <$objectproperty(#quest.thing#; punch)$>
}
end define

define options
debug on
panes disabled
end define

define room <IT-Room>

define object <obj001>
alias <ball>
look <You see a blue ball.>
prefix <a blue>
displaytype <Object>
article <it>
gender <it>
properties <push=You push the ball.; punch=You punch the ball.>
end define

define object <obj002>
alias <dog>
look <You see a brown dog.>
alt <brown; brown dog>
prefix <a brown>
displaytype <Object>
article <it>
gender <it>
properties <push=You push the brown dog.; punch=You punch the brown dog.>
end define

define object <obj003>
alias <dog>
alt <grey; grey dog>
look <You see a grey dog.>
prefix <a grey>
displaytype <Object>
article <it>
gender <it>
properties <push=You push the grey dog.; punch=You punch the grey dog.>
end define

end define


With two dogs, albeit different colors, I push them both when typing 'push dog'. Decidedly not user-friendly - I should be given a disambiguation here. Any solution? I got about as far as you did, when I realized that I'd need to disambiguate. The alt property is unreadable in Quest. One solution I can think of is to create an alternate alt property, then use InStr.

I think Im Dead
19 Jan 2007, 21:30
Well the easier solution for this aspect, rather than disambiguate in this step, it'd be preferred to store the object name instead of alias so that IT would always refer to the intended object, ie; last used.

Now disambiguation in the typical manner Quest uses, popping up a window to select the desired object, just isn't possible. However, analyzing each object in the room then giving a list option of objects with that alias, taking the choice then re-executing the original command while referring to the desired object name.

Now, I've complete a script which should do something along these lines, except that there appears to be a problem with Quest 4.0 as I'm getting a runtime out of range error due to a numeric variable resting inside of a string variables name. It could be my coding, although I'm quite sure that I've used numerics inside of strings a thousand times prior to 4.0. Either way, here's the code, albeit unfinished due to being unable to process the list, but here's hoping Alex reads this post and can clarify if it's a true bug or not.

P.S. I have tried the numeric both inside and outside of [ ] brackets, to no avail.


beforeturn {
if ( $lengthof(#quest.input#)$ > 0 ) then {
set numeric <dis-obj-count; 0>
for each object in <#quest.currentroom#> {
if ( $objectproperty(#quest.thing#; alias)$ = #quest.input# ) then {
set numeric <dis-obj-count; %dis-obj-count% + 1>
set string <dis-obj[%dis-obj-count%]; #quest.thing#>
}
}
if ( %dis-obj-count% > 1 ) then {
msg <Which object did you mean?|n>
for <i;1;%dis-obj-count%> {
msg <%i%. $displayname(#dis-obj[%dis-obj-count%]#)$|n>
}
}
' Selection of applicable object choices code would go here.
}
}
command <push #quest.input#> {
for each object in <#quest.currentroom#> if ( $objectproperty(#quest.thing#; alias)$ = #quest.input# ) then msg <$objectproperty(#quest.thing#; push)$>
}

Alex
19 Jan 2007, 22:14
The correct syntax would be #dis-obj[dis-obj-count]#.

As for the rest of this thread, I'm somewhat baffled. I think a feature request would be simpler than all of that code... but maybe less fun :)

Overcat
19 Jan 2007, 23:59

As for the rest of this thread, I'm somewhat baffled. I think a feature request would be simpler than all of that code... but maybe less fun



More fun and probably (if solved) more expedient than waiting for the next release. Of course, this exposes problems and transmutes them into requests.

What you've done, ITID, is made your own disambiguation menu, albeit in-game rather than in a popup. I did a similar thing earlier, here, (if you follow the thread a bit). This was the same solution I was thinking of, except yours is much smaller and cleaner than what I was going to attempt.

Well, I'm off to feature request.