So I'm trying to fill my game up with lots of little cosmetic interactions... Like sitting down on a chair when you touch one. Made a sprite of a guy sitting down on a chair. Tricky part is making it functional.
See, making the hero sit down is easy enough. Made a chair event, set it to touch trigger, and if the hero touches it he changes to his "sitting down" sprite. The problem is, I can't check if the hero is -not- touching an event. So I can't change his sprite back.
I've thought of two ways I could do this. I could either put the hero's coordinates in variables, and change his sprite to normal when his coordinates do not match those of the chair. Or I could surround the chair with touch events that change the hero sprite back. Both are pretty convoluted for something as simple as sitting down on a chair.
Maybe I'm thinking too hard about this and there's a simpler way, but I can't come up with one. Anyone have ideas?
Why not just detect pushing the movement keys? You'll have to catch other keys if you want them to work, but you can put it the next page of the chair event.
Checking button pressing may be better anyway, because surrounding events may be triggered too late. The character would move in his sitting pose for a bit before the event triggers and changes the graphic to the walking sprite. Just have a loop inside the chair event and check for all direction and, if you want, the menu. Since you're using RPG Maker 2000/2003, make sure to have some wait frame(s) inside the loop so the lag is reduced. (I think in MV this isn't an issue anymore.)
I thought about doing this, tried it out. It looks like I don't even need a loop. I just put a key input and change the hero graphic after that.
By the way, do you know if you can re-use the same variable for key inputs throughout the game? I'd rather not make a special variable just for this one chair.
As long as you make sure it is reset properly, sure, why not. 🙂 Variables only store a number after all, not more and not less. There is no such thing as global vs. local variables or scope in RPG Maker.
Okay, found a problem with this method... If you have an action key triggered event right in front of the chair, say, a book on a table, it doesn't work while sitting on a chair. I can't enable the action key button in the chair event, because if I do that than the variable will be set to a number that does not correspond to one of the arrow keys. And then if you move, you stay in the "sitting down" sprite. But if I don't enable the action key, then I can't interact with the book while sitting down, which is dumb.
This is getting pretty frustrating...
Without knowing what you're doing with the variable you mention, it's hard to understand what the problem is.
The variable for the key input. When a key is pressed, the number corresponding to that key is stored inside the variable you selected. If I'm sitting on the chair, and I press the enter key, it stores the number "5" in that variable, while the arrow keys correspond to numbers 1-4. Since it's a touch event, it only stores the variable once when a key is pressed, and so if enter is pressed, and you then press the arrow keys, it doesn't store the numbers of the arrow keys in the variable. Which means the sprite doesn't change back.
Can you screenshot your chair event and post it?
I'm thinking you can add a branch for the key input to be 5, and put your event interaction code there.
If I set the variable back to 0 in the conditional branch that checks if the Enter key is pressed, and I wrap the whole thing in a loop, that actually works. But only if I add the dialog from the event on the table to the chair event itself. Kinda wanted to avoid that, but I guess there's no choice.