Chapter 6
(incomplete)
The LINK object
How to affect one object with another
The biggest problem the early scripters had to overcome, was the lack of ability to access other objects via a script. The only two objects possible to access were the SRC and the default object. And the LINK. The LINK made it possible to do things in version .40 that most people don't suspect are possible even in SPHERE .55i.
The LINK property of an item holds the UID of another object. Then, it serves as an object reference to directly access that object. The LINK property can be set in-game or in a script. Here's an example:
[ITEMDEF i_link_test]
ID=01828
NAME=Link Test
ON=@DClick
- MESSAGE The LINK's name is <LINK.NAME>.
- RETURN 1
Now, create this item in-game and set its LINK to the UID of another object. (Use the .info command or .xshow uid to get the UID.) Double-click the Link Test item. It will say the name of the object you linked it to. This obviously has very little use, so here I offer you a piece of a script I wrote a while ago that uses the LINK object. (The items have been changed to protect the innocent.)
[ITEMDEF i_tile_sender]
ID=01828
NAME=Sender tile
ON=@DClick
- IF (!<LINK.UID>) // If there is no link yet
- TARGET Select an object to link to.
- RETURN 1
- TARGET Select an object to link to.
- ELSE
- LINK.SAY <SRC.NAME> is knocking at your door!
- RETURN 1
- LINK.SAY <SRC.NAME> is knocking at your door!
- ENDIF
ON=@TargOn_Item
- LINK = <SRC.TARG.UID> // Put the UID of the targeted item into LINK
- RETURN 1
ON=@TargOn_Char
- LINK = <SRC.TARG.UID> // Put the UID of the targeted character into LINK
- RETURN 1
This script has no real apparent use either, but put the item in front of a house, and let the house owner link it to an item of his choosing. (He would probably want to link it to his backpack because he'll have that with him all the time. He might even want to link it to himself.) When someone comes to his house, they can double-click the tile, and the house owner will get a "Knock knock" style message so he can go see what's happening at his house.
Do you understand the script? You should understand the part dealing with the IF statement, and the TARGET function. If you don't, reread the script until you do, or the earlier chapters dealing with those particular aspects of scripting. The only part here that's new is the LINK.SAY function, which causes the LINKed item to SAY whatever the scripter wants.
Another use for a LINKed object becomes apparent in the next chapter when we discuss the @Timer event. @Timer has no SRC, so you must find another way to access items outside of the script. LINK is just the tool for that. Read onward!