[SOLVED]Questions about "use on"

chellkafka
So, I have this game where you have to make objects "real" before you are able to interact with them. If you try to interact with an object before you made it "real", an error-message appears. And the problem I have with "use object 1 on object2" is, that I want it only to work when both objects are "real".
I tried it like this (let's say with "paper")


If (paper.real=true) {
if (object2.real=true) {
msg ("You use the paper on that.")
}
else {
msg ("error!")
}
}
else {
msg ("error!")
}


my idea was that "object2" would refer to any object the player would type in after "use paper on", but it doesn't.
Any ideas how to go about this?

Silver
I would make two objects for each object, a real one and an unreal one. You hide the real ones in a room that isn't connected to the game. When you make the object real you simply swap the unreal one for the real one. That way you can give them independent behaviours and descriptions but the player just thinks it's the same object that has changed.

Silver
I think with what you're doing you need to do

if (paper.real=true) and (object2.real=true) {

Silver
I really need to read posts properly.

I'm not sure how to do this - unless you can check for an expression.

If (#object#.real=true)

Something along them lines - I'm thinking out loud lol.

But then how will it handle the different scripts for the different objects? I think you have to handle them all individually.

The Pixie
I think you will need to create a new command, rather than use the built-in USE facility. Put in a pattern like this, then it should work as you expect.
use #object1# on #object2#


if (object1.real=true) {
if (object2.real=true) {
if (object1 = paper) {
msg ("You use the paper on that.")
}
if (object1 = ball) {
msg ("You use the ball on that.")
}
else {
msg ("..")
}
}
else {
msg ("error!")
}
}
else {
msg ("error!")
}

Unfortunately, you do now have to put in code to allow for each object in your game to be used, and if you have only half a dozen objects, that will get messy. What you could do is set up a script on each object, say called "usescript", and call that (with "invoke", so we can use object2 as a local variable in the script).
if (object1.real=true) {
if (object2.real=true) {
object1.object2 = object2
params = NewObjectDictionary()
dictionary add (params, "object2", object2)
invoke (object1.usescript, params)
}
else {
msg ("error!")
}
}
else {
msg ("error!")
}

Your "usescript" (set up the attributes tab) on paper might look like this:
msg("You use the paper on the " + object2.name)

chellkafka
Would you care to elaborate on the script? I'm genuinely interested in what all the single elements are and what they do.

The Pixie
I now see I have an extra line; I have commented it out below.
if (object1.real=true) {
if (object2.real=true) {
//object1.object2 = object2
params = NewObjectDictionary()
dictionary add (params, "object2", object2)
invoke (object1.usescript, params)
}
else {
msg ("error!")
}
}
else {
msg ("error!")
}

The invoke script command calls a script, and for the duration of that script the values in the second parameter, a dictionary, will be local variables. So:
    // Create a new dictionary
params = NewObjectDictionary()
// Put values into it, only one in this case
// The local valiable will be called "object2" and will be assigned the same value that object2 currently has
dictionary add (params, "object2", object2)
// Then call invoke
// The first parameter is the script, which is called "usescript" and is on the object called object1
// The second parameter is the diction we just created
invoke (object1.usescript, params)

chellkafka
So, I created a "use on"-command as you suggested and it works! So that's great, thank you.
But what I don't understand is that "usescript" of yours. I didn't implement it and the "use on"-command worked just fine. Why would I need that? And please keep in mind, I don't understand anything really of programming and how quest5 works (in general).

The Pixie
I have no idea how it can work if you do not have "usescript" set up on object1. Are you sure about that?

In general terms, a script is some software code attached to an object. The new USE command we just created is an object, and it has a script that gets run when Quest matches the command - the script above. In that case the script is called "script", but they can be called anything you like. The script called "script" on the USE command calls another script, "usescript" on object1.

So what you should have is a script called "usescript" on each item in the game, such as the paper. Then you can write each of these scripts to be specific to that item - because using the paper on something will be different to using something else on it.

Does that make sense?

chellkafka
Well, I did use a script, obviously, but I meant that script with the dictionary and the invoke, etc. That I didn't use and it works.
I mean, I included a check for the object names, so it gives for every object a different response. Like this:

if (object1.real=true) {
if (object2.real=true) {
if (object1.name="paper") {
msg ("You can't use the paper like that!")
}
else if (object1.name="pen") {
if (object2.name="paper") {
msg ("You wrote something.")
}
else {
msg ("You can't use the paper on that.")
}
}
else {
msg ("error")
}
else {
msg ("error")
}
else {
msg ("error")
}


So, I don't know, shouldn't I do it like this?

The Pixie
Ah, I see. There is more than one way to solve the problem. Your way will certainly work, and if you are not following how the dictionary/invoke way works, stick to that.

However, if you have several objects in your game, each can be used on another, you will get a huge script for the command. It would be better IMO to break it up, keeping the script for one object with that object.

chellkafka
Sorry, that I reply so late, but I wanted to thank you, Pixie. I just followed your instructions and it worked, so thanks a lot. Again, I know a little more.

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

Support

Forums