'Carrying Object' script not working for me.

OurJud
I suspect (as usual) I'm making a fundamental mistake here, but I can't get the 'if carrying' script to work.

I describe a room with a coffee table, on which lies a handgun and cellphone. If the player takes the handgun (but not the phone), then moves to, and back from, another room, I want the description to say that there is now only a cellphone on the table.

So, in the room tab, I run the following script:

'If' player is carrying 'gun', print: "There is a cellphone on a smoked-glass coffee table."

'If player is NOT carrying 'gun', print: "There is a cellphone and a handgun on a smoked-glass coffee table."

So when I start, both objects are there. So I take the gun, exit to the kitchen, then come back, and the message which takes away the gun doesn't display. It still shows the message saying both items are there.

Ultimately, I want to do the same if the player takes the cellphone but not the gun, and also have a description for if the player takes both.

OurJud
Okay, I've now managed to do the phone logic with Silver's good ol' reliable flagging method, but I'd still appreciated an explanation as to why the carrying script didn't work for me.

jaynabonne
What you say seems reasonable, so I assume it must be a simple error somewhere. Any chance of posting your game? :mrgreen: That would be the easiest way to work it out.

Or attach a simple sample game that exhibits the problem?

OurJud
I've just seen there is a few options in the script tab. Let me try in there, as there is a 'after leaving the room' option.

OurJud
No, that's not working either.

I'll set it up in a test game and post it.

The Pixie
It is not whether the gun is being carried, it is whether it is in the room. The player could pick up the gun, then leave it in another room, and then come back. Not carrying it, so the description says the gun is on the table!

Someone asked a related question a few days ago. Take a look here, it describes how to change a Quest function, so you can then use the text processor to do this sort of thing.
viewtopic.php?f=10&t=4779&p=31597#p31597

Alternatively, set the If to "expression", rather than "player is carrying object", and type in (if "gun" is the object name):

gun.parent = this

OurJud
Well, the carry script worked on my test game.

I'm quickly discovering the TA worlds are an absolute mine field, and I'm not making things any easier by disabling hyperlinks. Maybe I over-think things, but now because of what TP has just said, I'm fretting about 'drop' logic. My player is carrying the gun, goes into the kitchen and for whatever reason 'drops' it there. This means that the kitchen description now needs to say 'there is a gun here'. Arrrghhh!!

I'll try the 'if gun' thing.

jaynabonne
I'm not sure if this would help, but each object can have an "in-room" description that is added into the room description. To enable it, click on "game", go to "Features" and check the bottom checkbox. Then go back to your gun and there will be an additional text line where you can put in text that will be added to the room description.

It's not conditional, so it would have to be the same for all rooms (unless you use The Pixie's change to allow conditional text processing per room).

OurJud
This is what I now have and it don't work. Nor does the same set up with 'player is carrying' selected instead of 'expression'

Any ideas?
screengrab.jpg

Silver
Or you just don't allow the player to drop the gun once picked up. :mrgreen:

Silver
You're going about this in a very complicated way. The game lists objects in rooms by default as long as you haven't set it as a scenery item.

OurJud
Silver wrote:You're going about this in a very complicated way. The game lists objects in rooms by default as long as you haven't set it as a scenery item.

I suspect I am, but I don't use hyperlinks, so have no choice but to do these things via my descriptions.

Silver
OurJud wrote:

"Silver"

You're going about this in a very complicated way. The game lists objects in rooms by default as long as you haven't set it as a scenery item.


I suspect I am, but I don't use hyperlinks, so have no choice but to do these things via my descriptions.



No. Switching off hyperlinks only switches off hyperlinks. You've also disabled objects being listed. That's a different option.

OurJud
Silver wrote:

"OurJud"

[quote="Silver"]You're going about this in a very complicated way. The game lists objects in rooms by default as long as you haven't set it as a scenery item.


I suspect I am, but I don't use hyperlinks, so have no choice but to do these things via my descriptions.



No. Switching off hyperlinks only switches off hyperlinks. You've also disabled objects being listed. That's a different option.[/quote]

Oh, hold on, then.

OurJud
Mmm, there's something wrong here!!

I enabled the objects hyperlink (I don't like it, but it was just a test), and even when I take the gun, leave the room and come back, it still lists the gun as being there??

It's little worrying that I could get the 'if carrying' script to work on the quick test game I did. Suggests my real game has picked up a bug, no?

jaynabonne
The code you showed worked for me when I put it in my game.

Do you have more than one gun? If you type "inv" after taking the gun, does it say you have it?

Did you turn on "object can be taken" for the gun?

This is where it really helps to have the actual game file!

Silver
Have you deleted the script you implemented?

OurJud
jaynabonne wrote:Did you turn on "object can be taken" for the gun?

:oops: :oops: :oops:

OurJud
Phew!!

Sorry, everyone. The fact that my 'You take the gun and slip it into your trouser waist' is triggered when I take the gun, meant I never even considered this. I don't know why I didn't tick it initially.

Anyway, the script work now. Now I just have to figure out how to do it phone only and if both have been taken.

No, Silver, I haven't deleted the script.

Silver
You can do what you're doing (mentioning the objects in the description then checking flags to change the description) and set the objects to scenery. When you pick a scenery object up it changes from scenery to a normal object so you don't need to worry about writing more scripts if they get dropped again.

However you still need object descriptions to be switched on. I'm afk at the moment but from memory you disable/enable objects being listed where it asks you the order you want descriptions, room titles, directions etc. if you set it to zero it switches it off iirc.

OurJud
I'm still struggling to get my head around your last post, Silver.

For now, I'm not allowing drops (life's too short), Instead, I have a message saying "You think twice and decide to keep hold of it for now".

What I'm struggling with now is getting the 'object there/not there' with the other object (cellphone)

I've successfully managed to do it with the gun, using a combination of 'carrying/not carrying' scripts, but can't figure out how to do it with the cellphone and if the player takes both items. If I simply run another 'carrying/not carrying' script for the cellphone, I get the room description twice when I run the game.

jaynabonne
This is where things get interesting. You have two things (gun and cellphone) each with two states (got or not). This means you have four possible conditions:

if (Got(gun)) {
// Have gun
if (Got(cellphone)) {
// have both gun and cellphone
} else {
// have gun only
}
} else {
// Don't have gun
if (Got(cellphone)) {
// have cellphone only
} else {
// have neither
}
}


Fill out those four cases. They are all exclusive.

Silver
Remember you have to work backwards to how you think. So you need to check 3 things.

The first thing you check is if neither the phone or gun are there. Then you print description just describing the empty table.

Next you can check if the gun isn't there. If it isn't print the description with the phone on the table.

Next the same for the phone giving the description of the gun on the table.

The final else checks for no flags and just prints that there's a table with a gun and phone on it.

OurJud
Thanks.

Jay, where would I put that code?

And Silver, I've only used 'carrying' scripts so far. You're saying use flags, yes?

jaynabonne
Where you currently have your code. The code you're trying to extend to handle both the gun and cellphone. You'll need to add in the actual text you want printed out, but it gives the overall structure.

OurJud
jaynabonne wrote:Where you currently have your code. The code you're trying to extend to handle both the gun and cellphone. You'll need to add in the actual text you want printed out, but it gives the overall structure.


So I just use text instead of script, paste that code in and fill in the blanks?

jaynabonne
Yes, you can do that. Failing that, you can just reconstruct the structure in the Quest editor.

OurJud
Ooh, it's another one of those nights.

I just put all that code into the text message and it displayed all the code too.

If I add all these conditions, it just displays the room description multiple times.

jaynabonne
If you have the else's, it shouldn't. It's another case of needing to see the code to see where it's gone wrong.

OurJud
So do I upload the game as an attachment?

OurJud
This is what I have:

if (Got(gun)) {
msg ("There is a smoked-glass coffee table on which sits a cellphone.")

if (Got(cellphone)) {
msg ("There is a smoked-glass coffee table here.")

} else {
msg ("There is a smoked-glass coffee table on which sits a cellphone.")
}
} else {
msg ("There is a smoked-glass coffee table on which sits a gun.")

if (Got(cellphone)) {
msg ("There is a smoked-glass coffee table on which sits a gun.")
} else {
msg ("There is a smoked-glass coffee table on which sits a gun and a cellphone.")
}
}

OurJud
The above, pasted into 'code view' on 'run script' gives:

There is a smoked-glass coffee table on which sits a gun.
There is a smoked-glass coffee table on which sits a gun and a cellphone.

Silver
Edit - didn't realise there was posts.

jaynabonne
You have six outputs there. You only want four. (I'm sorry my code comments confused you. They were meant to indicate the decisions made at each point, not necessarily places you had to put messages.) It should be this for the four cases:

if (Got(gun)) {
if (Got(cellphone)) {
msg ("There is a smoked-glass coffee table here.")

} else {
msg ("There is a smoked-glass coffee table on which sits a cellphone.")
}
} else {
if (Got(cellphone)) {
msg ("There is a smoked-glass coffee table on which sits a gun.")
} else {
msg ("There is a smoked-glass coffee table on which sits a gun and a cellphone.")
}
}

OurJud
That did it. Thanks, Jay.

I had given up on this and decided I'd only ever have one object per room because the implications and work involved for setting up the player's logical options were killing my enthusiasm.

I've studied that sequence and the nesting, and I'm still not sure I understand - certainly not enough that I'd have got there myself.

I know that in plain English, the logic is:

If I have the gun and I have the cellphone, neither should be on the table, but if I only have the gun, the cellphone should still be on the table, unless I only have the cellphone, then the gun should still be on the table. If none of this is true, then both the cellphone and the gun are on the table.

Even written out in plain English I'd find it impossible to convert with the UI.

Silver
Why don't you just re-enable the object list?

OurJud
Silver wrote:Why don't you just re-enable the object list?

I don't really know what you mean. I know the object list handles pick-up and drops automatically, but I include my objects in my descriptions so I don;t see how this would solve anything. The alternative is to have them as links, but I don't like that. I know you said I can turn them off by setting the value to 0, but I'd still need to adjust my descriptions depending on what the player may or may not choose to pick up.

Unless I'm not understanding.

Silver
Yes you misunderstand. When it is enabled it automatically lists the objects that aren't set as scenery objects. The same as directions are listed if you have that enabled. So, depending on the order you have set you will get this:

Chamber
You are trapped in a chamber. The air is stale and humid. The grey walls are blah blah.

You can see a knife and a set of keys.
__________

The game generates that second line about objects if you have it enabled which means you won't have to write scripts for when they are taken or dropped. But you have it disabled for some reason.

OurJud
Silver wrote:Yes you misunderstand. When it is enabled it automatically lists the objects that aren't set as scenery objects. The same as directions are listed if you have that enabled. So, depending on the order you have set you will get this:

Chamber
You are trapped in a chamber. The air is stale and humid. The grey walls are blah blah.

You can see a knife and a set of keys.
__________

The game generates that second line about objects if you have it enabled which means you won't have to write scripts for when they are taken or dropped. But you have it disabled for some reason.

Yes, I have it disabled because, as I said, I like to include my own descriptions of objects. I don't want every room description to end with a simple, "You can see..." sentence. It becomes too formulaic for my tastes. I appreciate how much easier that would be for me, but it's not how I want my room descriptions to read.

However, now that I have a working "is carrying object" script, I can simply copy and paste it over from the code view and just change the objects and descriptions for any room where I choose to have two gettable objects.

Silver
Well I employ both methods. For each to their own.

OurJud
Silver wrote:Well I employ both methods. For each to their own.

Out of interest, how do you blend the default "You can see..." sentence into your own descriptions, then? If you use the default object lists, I don't see how your descriptions can avoid having that sentence tagged on the end each time.

Silver
I mean I would adopt the method you use but not absolutely avoid the other. It would be too difficult to avoid object lists. Such as you now making it that objects can't be dropped in order to avoid having to write scripts for every eventuality.

But what I mainly do is have objects as scenery items that have to be 'discovered'.

OurJud
Ah, I see. Maybe I'll play around with the idea. See if I can get on board.

OurJud
I'm beginning to wonder if there's something mentally wrong with me, as nothing seems to work in this game until I've had four pages of help on it.

The thing is, I didn't even consider the fact that this wouldn't work, but it doesn't and I can't work out why.

All I want to do is have the game print one of two possible messages depending on whether or not my player is carrying an object at any given moment.

So there's a gun on a table at the start of my game. On that gun's 'Use/Give' tab I run a script which says If the player is carrying the gun, print: "You pull out your gun." If he's not carrying the gun print: "You reach for your gun only to discover it's not there."

I want this to run regardless of where the player is in the game, but it only works while I'm in the same room as the gun. If I navigate to different areas, purposely leaving the gun behind, then type: 'use gun', I get the message: "I can't see that."

What do I need to do so that it checks whether the player is carrying the gun regardless of where he is in the game?

jaynabonne
Basically, using the built-in "use" command, you can't use something if it's not there. Just as you can't look at it, take it, etc.

To make "use gun" work everywhere, create a command with the explicit command pattern "use gun" (same steps as for the "use lift" one). This time, be sure it's in the Command list under *game* instead of a specific room, so that it will be in effect everywhere.

OurJud
jaynabonne wrote:Basically, using the built-in "use" command, you can't use something if it's not there. Just as you can't look at it, take it, etc.

To make "use gun" work everywhere, create a command with the explicit command pattern "use gun" (same steps as for the "use lift" one). This time, be sure it's in the Command list under *game* instead of a specific room, so that it will be in effect everywhere.

Cheers, I shall go give that a go.

Wonderful. Thank you.

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

Support

Forums