Using a key on a door(SOLVED)

Started by proskiier, Sat 10/11/2007 03:22:21

Previous topic - Next topic

proskiier

I searched around the forum and only found one post that kinda helped me, but it was incorrect code so i didnt want to use it


Basically I have a simple map with a key on the ground that when clicked with the hand goes into inventory and is named "iKey" which i learned through the tutorial and did in the interaction thing, but I want to make it so that if you click on the door with the hand it says this door is locked.  But (you guessed it) when you use the inventory key it says the door is unlocked, and also removes the key from your inventory/allows you to now click the door with the hand cursor and go inside(load a new map).

with this best be done with the room script??? or can this be done easily with a few lines in the "room script"


sorry i am new and don't really know how this all works so far... wish there were more tutorials >.< the first one helped sooo much

quixotecoyote

#1
Welcome to the wonderful world of 'if' statements and variables.

Open up your room script.

at the top put

Code: ags

bool doorlocked = true;


This will set a true/false variable that keeps track of if the door is locked or not.

Now open up the interaction menu for the door.
Set a run script action under use inventory item on object.  (or use inventory item on hotspot if you have the door as a hotspot).

Now you write an if statement:

Code: ags

if (cEgo.ActiveInventory == ikey) {
  doorlocked = false:
  Display ("The door is unlocked");
  cEgo.LoseInventory(ikey);
}

If you are using the key, this sets the doorlocked variable to false, shows a message, and disappears the key.

Next go to the interaction editor and set a run script action under interact with object (or hotspot as the case may be) and put two if statements.
Code: ags

if (doorlocked == true) {
 Display ("The door is locked");
}

else if (doorlocked == false) {
  cEgo.ChangeRoom(x);
}

If the door is not locked, you move to another room.
If the door is locked you get the message and nothing else happens.

proskiier

thank you so much I cannot tell you how helpful this was... I took a c++ class but I got a D in it because it was so hard for me. But this is kind of bringing it back.

Is there any like tree of functions anywhere or a list of all the new 2.72 ones??

also one more question, if I want to now have the door on my map just be a black rectangle (showing that it is always open) how would i do that??

Should i add a black rectangle shaped object (because I think i could possible be able to script that) or is there an easier way??

Thanks again so much, your suggestion really helped :)


p.s. just in case you repost it for someone more n00b than me, make sure you edit your "doorlocked = false:" colon into a semicolon  ;D

quixotecoyote

[qupte]p.s. just in case you repost it for someone more n00b than me, make sure you edit your "doorlocked = false:" colon into a semicolon  Grin[/quote]

Oops   :-[


And yeah, using an open door object that  isn't initially visible and then turning it visible in the same script that unlocks the door would be the easiest way to do that.

proskiier

awesome man thanks alot... really appreciate the help

hard to learn without the demo being available

the tutorial is great but can only get you so far

(if you have an answer/time would you check out my other post about getting all objects/hotspots names to show under the mouse or in the bottom corner like in the {cure a cold game} under the short game menu on the site)

and also when I go into my bedroom, I kinda made it way to big, is there any way to double my character size without redoing all the sprites??

gypsysnail

Ah I think I can help with this one... you will have to test it out a bit to get the right size. But here is how you start. Go to the room editor, go under Areas which is a sub category under Room Editor. See 'zoom level' - the number in it in %, you type a number, maybe it will be 50% or 200% or 30%, but keep trying different numbers til you get the size of the character you want for that room, also tick Continuous scaling, because this lets the character get smaller as it walks further north.

(please correct me if I'm wrong with the continuous scaling part but I believe thats what happens, if not, then it will be unticked for the character to become smaller with the perspective). I hope this helps. As I said, just keep testing from there. :D

Forgive me if I am posting in this post cos its already solved, but starting here sorry.
Believe in afterlife! It's true in a metamorphical way ;)
Ken & Roberta - my inspiration!! 20 years.
U are what you love doing and passionate about - keep up what you love most.

SMF spam blocked by CleanTalk