Current Object

echus
This is a very simple question, but I can't seem to find the answer anywhere. This is my first text adventure.

I'm trying to use the current objects in a Use/Give situation. In the first example, I am trying to code dropping an object into a bin which takes the object down a chute to another room:

msg ("You hear it rattle down the chute to somewhere else.")
IncreaseScore (10)
MoveObject (game.current_object, r28u)


results in...

You hear it rattle down the chute to somewhere else.
Error running script: Error compiling expression 'object': RootExpressionElement: Cannot convert type 'Object' to expression result of 'Element'


The second example is similar. I have a chest, which when closed causes the contents to vanish permanently.

foreach (thing, game.current_object.GetAllChildObjects()) {
RemoveObject (thing)
}


results in...


> put stick in chest
Done.

> close chest

The chest closes with a thump. Your skin prickles slightly with magic.
Error running script: Error compiling expression 'game.current_object.GetAllChildObjects()': FunctionCallElement: Could find not function 'game___DOT___current_object___DOT___GetAllChildObjects()'


Switching 'game.current_object' to 'chest.GetAllChildObjects' doesn't help. Nor does 'GetObject(chest).GetAllChildObjects()'.

These are the last couple challenges to complete my first project. Much appreciate any solutions! Thank you.

Silver
I haven't started understanding code so can't help on that front unfortunately.

But I'd set up a script to print message 'object falls down the chute...' and move object to location in the interface. Couldn't you do that then inspect the code to see how it's done?

jaynabonne
There is no "game.current_object" in Quest. I'm not sure since the code snippets you've given aren't complete enough to tell, but try using "this" where you've used "game.current_object". "this" has the value of the object that the current script is running on.

For example:

msg ("You hear it rattle down the chute to somewhere else.")
IncreaseScore (10)
MoveObject (this, r28u)


foreach (thing, this.GetAllChildObjects()) {
RemoveObject (thing)
}

echus
I should probably mention that I'm working from the web GUI. I'm not on a Windows system (and don't have access to one) which may limit my debugging ability.

For the first example, the 'this' pointer is the container object 'bin' instead of the target object:


msg ("You hear it rattle down the chute to somewhere else.")
IncreaseScore (10)
MoveObject (this, r28u)


This winds up moving the container instead of the object I am depositing in it.
Does the target object go into the container after the action callback? If so, is there a pointer to the acted on object?

The new output is...

> give stick to bin
You hear it rattle down the chute to somewhere else.

> goto r28u

This is a gray room with a yellow floor.

There is a hole in the ceiling. It is too small to fit through. It looks like a chute comes down from somewhere above.
The is a large open bin here.


In the case of the second example (a container close action), the new results aren't still an error:

foreach (thing, this.GetAllChildObjects()) {
RemoveObject (thing)
}


produces this output...

The chest closes with a thump. Your skin prickles slightly with magic.
Error running script: Error compiling expression 'this.GetAllChildObjects()': FunctionCallElement: Could find not function 'this___DOT___GetAllChildObjects()'


This must be very close to working... I sense that I am just slightly off on syntax.

jaynabonne
Again, I have no context for knowing where these scripts live, so I'm making blind guesses about what might work. If you can give more information, it would help.

I tried to replicate what you did for the first example. (Keep in mind I have the desktop version.)

- I created two objects, a stick and a bin.
- I went to the stick and enabled "Use/Give" under the "Features" tab.
- On the "Use/Give" tab, I scrolled down to "Give this to (other object)". I set the action to "Handle objects individually"
- I clicked Add and picked the bin.
- In the script, I printed out the value of this, and it showed the stick.

If you could give similar instructions to replicate what you're doing, then we can go somewhere.

For the second example, if the container is always the same, then you can just use the container name directly instead of "this".

jaynabonne
Actually, for the second case, it needs to be something like:

foreach (thing, GetAllChildObjects(this)) {
RemoveObject (thing)
}

If "this" doesn't work, then try the name of the container object.

HegemonKhan
if you got a 2nd and separate object, you'll need to use parameters.

'this' is a specialized 'GetObject' Function for the parent Object of~holding the script~verb that you're using.

(you might just be writing your scripts at~in the wrong spot too... if you want 'this' to act upon your 'stick' Object than you need to make sure you're adding your scripts to the 'whatever' Verb of the 'stick' Object, and not to the 'whatever' Verb of the 'bin' Object)

so, you'll have to use '(Functions):parameters', 'GetObject', and a way of selecting the Object that you want to get (for example: get input, if it's not dynamic then just write in the Object for the 'GetObject', show menu, and etc methods...)

-------

let us know if you still need more help (and again, as Jay is harping upon, we're really limited in providing help, until we can see your code, so we can see what you're trying to do, which tells us how and what we should craft in code for helping you in what and how you want it done).

jaynabonne
"this" is not a function - it's a parameter passed to scripts.

You only need to use GetObject if you have an object referenced *by name* in a *variable*. If you know which object you want to refer to directly, it makes more sense to just refer to the object rather than go through GetObject.

The reason I'm trying to get the setup for this is that normally a verb like "give stick to bin" has the second object already passed *as an object*. No need for GetObject even in that case, and definitely no need for get input. That's just needless complication given that the verb already supports it

If we can get how the OP has set this up, then it should be trivial to know what the existing parameter is that can be used.

echus
Thanks! I'm just getting back to this... in both cases the scripts are on the Use/Give of the receiving object. Since it could be any arbitrary object in the game dropped into the chest or bin: that is where I think my code needs to go.

@Jay ... I see how yours worked. For me, the 'this' pointer may not work because it will point to the container, not the target.
@Hegemon... I think you are close to the answer. I need to access the passed (target?) object of the call. I will study further.

Will tinker this evening and post progress, but thanks so far.

jaynabonne
For the give "stick" to "bin" case, where the bin is receiving, use "object" instead of "this". That is the parameter that receives the given object in this case.

msg ("You hear it rattle down the chute to somewhere else.")
IncreaseScore (10)
MoveObject (object, r28u)


"object" is just the name the Quest code happened to decide to use as the parameter name. :)

echus
Thank you! Have a solution to both problems... it was quite simple as I suspected.

msg ("You hear it rattle down the chute to somewhere else.")
IncreaseScore (10)
MoveObject (object, r28u)


I changed the chest that makes objects disappear to be very similar in functionality... works just as well (story-wise).

On to play testing! Now, where are my children?

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

Support

Forums