Interacting with Objects
This will show how to add an object to your room and interact with it.
Adding a Prop
First, go to the Game Explorer, and add the Box sample from the Toolbox’s Insert view sample menu. Give it resource number 123:
Next, go back to the rm110.sc script and place the cursor at the bottom. Right-click InsertObject->Prop. Give it a name theBox, and set its view property to 123 (this is the Box view included in the template game). It should look like this:
(instance theBox of Prop
(properties
view 123
x 150
y 100
signal ignAct
loop 0
cel 0
noun N_NOUN
priority 0
)
)
However, this won’t compile properly yet, because we have given it a noun that doesn’t exist. You can just remove the noun property altogether, but we want to actually interact with this box. So go to the message resource for script 110 (use the Messages link in the Toolbox pane). Add a new noun, and call it N_BOX (see Message editor to learn how to do this). Save the message resource and return to the script. Set the noun property of theBox to N_BOX:
(instance theBox of Prop
(properties
view 123
x 150
y 100
signal ignAct
loop 0
cel 0
noun N_BOX
priority 0
)
)
We’re not quite done yet! In addition to declaring a Prop, you need to initialize it. This makes sense, since you might not always want Props to appear right away in a room. So go to the room’s init() method and add this to the end:
(theBox init:)
Now compile and run, and you should see the box in the center of the room:
Interacting with a Prop
That was the hard part. Now the easy part.
Suppose we want to display a message when the player looks at the box. To do so, add a message for the LOOK verb on BOX:
Save the message resource and run the game, and try to look at the box:
The ego will turn to look at the box and the message will be displayed. Easy, right? You can add more messages to handle different verbs on the box.
Approach Verbs