Make object unuseable if switched off.

(Desktop Version)
The subject line says it all.
I'm modifying my computer again. I added the option to make it a switchable item. It's switched off at the start of the game. However the player is able to use it regardless of its state.
How do I make it say "The computer is off." if the payer tries to use it while it's off. I'm wanting to have the player need a keycard to turn it on.


Assuming you have a "use" verb for the computer. If not, you can do the same with whichever verb the player actually enters to use it.

Within the "use" script, you could have:

if (GetBoolean (this, "switchedon")) {
  // the rest of your 'use' code goes here
}
else {
  msg ("It isn't switched on.")
}

If you also want the "use" button to disappear from the menu, then in your "After switching on the object" script you could have:

this.displayverbs = ListCompact (ListCombine (this.displayverbs, Split("Use")))

and in the "After switching off the object" script:

this.displayverbs = ListExclude (this.displayverbs, "Use")

And if the computer starts turned off, then remove "Use" from the displayverbs (on the 'object' tab in the editor)
Note that when you do this, the player can still type "use computer", so the 'use' script should check if it is switched on.


The way I have it set up is by overriding the use function. Pixie showed me how in this post
but every time I try to modify it with an if statement it gives me a listcount error while the computer is off. I have it set up exactly the way he showed me there.
Can't figure out why I'm unable to get it to work. I must have tried over 20 different variations now.
I've been using:
if(not IsSwitchedOn(stasiscomputer)
and
if(IsSwitchedOn(stasiscomputer)
Basically all I want is instead of the computer menu appearing, is a message saying it's off.


Ah, I see the issue there.

You're stopping it creating a list of objects that the computer can be used on, but it's still trying to show that list to the player, and showing an error because it can't find the list. Don't check for IsSwitchedOn in the CreateUseMenuList.

To stop the menu showing up, you would add:

this.use => {
  msg ("It isn't switched on.")
}

to the "After switching off the object" script (and in the initialisation or start script, if it's initially off)

And in the "After switching on the object" script, you have:

this.use = true

to set it back to the "handle objects individually" behaviour.

Note that the script on the 'Use' tab (the one that actually handles using the computer on a pod) should probably still check for it being switched on; because even if you disable the menu of usable objects,the player could still type "use computer on pod 1".


Perfect! Thank you mrangel.
It works just like I wanted it to.
Only thing I did different is have the option checked to have it on at game start and use the start script to switch it off.

Just needs some fine tuning with the text.

I feel like I'm spending way too much time on this computer. I hope it's worth it. (I like it.)


Log in to post a reply.

Support

Forums