|
Post by Chatter on Nov 20, 2004 16:54:41 GMT -5
Hello
I have different rooms in my RPG. When I find a key in one room, then in another room the door obj has to know that it has to change if my hero touch that door. I know that i can make the whole program thing in my hero obj. But is there no other way? Because I get a whole lot of coding then in my hero obj.
Chatter
|
|
|
Post by Xenith on Nov 20, 2004 17:04:32 GMT -5
can you rephrase that? i'm not quite getting what you're saying
|
|
|
Post by Chatter on Nov 20, 2004 17:10:50 GMT -5
Xenith
Well, I have an chest in one room. In that chest my hero find a key. On the moment he gets that key a variable is set to 1. Now my hero leaves that room and comes across a lot of different other rooms untill he finds that particular room with the door that that key can open. How do I let the door obj know that this var is set to 1 and it has to open? I do not want the code in my hero obj, so is there another way to do that?
Chatter
|
|
|
Post by Xenith on Nov 20, 2004 17:37:02 GMT -5
oh i think i got you,
i think you'll have to learn how to make an inventory first, i never learned i think it's best to get help from ismavatar, she knows alot about that stuff, i guess you'll have to wait for her to reply
or if you wanna do it in a cheap way you could just do this,
when you get the key set global.key=1 and when you go to the door make it check if global.key=1 and if it does it'll let you through
|
|
|
Post by Chatter on Nov 20, 2004 18:16:04 GMT -5
What is a global.key? That seems that is a key for all the obj that is a door ? I don't need a inventory. I partially solved this problem by putting the code into my hero obj, that one is persistent. Only if i have to open 20 doors and fight with enemy's obj also, and all that code has to go into my hero obj, then that's a lot of code in my hero obj. I think there has to be a simpler way to do that. Chatter
|
|
|
Post by IsmAvatar on Nov 21, 2004 10:40:08 GMT -5
An inventory is not necessary if all you are collecting is keys. But a similar concept would do the trick, just leave out a great majority of the difficult coding behind inventories (like you don't actually have to draw the inventory ever).
The key principle is to use global variables, like Xenith suggested. Global.key = 1 This way, the variable belongs to nobody (such that if the object that created it goes away, the variable is still there), it simply exists. Global variables are also carried through rooms.
So, when you pick up the key, global.key = 1 When you touch the door, if global.key = 1 then image_single = 1 //open the door
|
|
|
Post by Chatter on Nov 21, 2004 15:26:49 GMT -5
hi
If I am understanding you correct then does the word "global " the trick. So when I make an obj as a chest in one room and my hero finds a key in that chest then I make global.key = 1 Now my hero walks thru the other rooms and enters the room with that door. In that door obj I have "if global.key=1 then change obj into open door obj. So if I make another key I can name that one global.key01 and offcourse that one is for another door. Am I correct?
Chatter.
|
|
|
Post by IsmAvatar on Nov 21, 2004 16:09:50 GMT -5
That is correct. If you have several keys, you can use the inventory concept some more and throw in arrays.
global.key[0] = 1 global.key[1] = 1 global.key[2] = 1
And if you're more advanced, you can figure out some neet tricks to save you from having to make 10 different objects, 1 for each key.
Here's an example: When you place the key in the room, Hold Control and then Right Click the key. Click "Creation Code". Type "mynum = 1;" (no quotes), where the 1 is the key number. Then, in collision with player, "global.key[mynum] = 1" (no quotes). You can do something similar with the door, as well.
|
|