I've recently started some basic scripting in RMXP, creating a CMS and some random menus to get some experience and inspiration.
I'm currently working on an item menu, and all but one of the features in it are working fine.
I want to swap from one menu to another when "UP" is pressed on the top row of the first menu, but there seems to be a small problem in my script. The transition to the other menu does work, but it also happens when I press up in the 2nd top row.
here's the update method for the menu I want to switch out of:
def update_item
@item = @item_window.item
@itemdesc_window.update(@item)
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu2.new(1)
elsif Input.trigger?(Input::C)
$game_system.se_play($data_system.buzzer_se)
elsif @item_window.index < 2 && Input.repeat?(Input::UP)
$game_system.se_play($data_system.cursor_se)
@item_window.active = false
@keyitemstitle_window.active = true
@keyitemstitle_window.index = 0
@item_window.index = -1
end
end
I've looked at some other people's menus, doing similar things, but I can't figure out why mine is not working, because it seems very similar. I've tried using Input.trigger? instead of Input.repeat? I've also changed my update_cursor_rect method to someone else's (from a menu where the feature was working) but to no avail. I was wondering if someone could help me with that.
In a nutshell: even though the menu is only supposed to change on the top row (when the index is 0 or 1) it also does it on the row below it.
I did notice, however,that it is briefly on the top row after I press up on the second row, since it very briefly shows me the top row's item description in my help window.
It should work, unless the '@keyitemstitle_window' is not handling the situation properly when it becomes active. I can throw some general pointers regarding scenes like this. First, I'm assuming that the update method in your Scene_Item has something like:
@keyitemstitle_window.update if @keyitemstitle_window.active
If not, do it. Observe how control switches to the actor status window and back in the regular menu scene.
Next, you can use the 'p/print' command to trace program flow:
p 'blah' # Shows a window with 'blah' on it
p @variable # shows a window with the value of the variable on it
Just use that to trace the point of problem so you understand the problem better. All the best :)
If only "should work" would actually work :P
It seems to me like it changes my menu's index to 0 BEFORE it processes the Input.repeat? command. Is that at all possible? and if so, what could I do to change it?
You mean only the first part is being evaluated in
elsif @item_window.index < 2 && Input.repeat?(Input::UP)
Give me a sec and I'll confirm... I'll edit this post.
EDIT:
Nah, the elsif works fine.
QuoteIt seems to me like it changes my menu's index to 0 BEFORE it processes the Input.repeat? command. Is that at all possible?
Not possible from the code in your post. Remember, a window can still be active with its index <0, and inactive with its index >=0. Dunno, it might have to do something with the update method of that key items window. You said you used someone else's code for update_cursor_rect? Now that I think about it, you don't need to mod update_cursor_rect for this to work. At least, so I think.
EDIT2:
Okay, tested it with an other script of mine, which has an item grouping system (items, equipment, key items).
I'll describe what happens when I try to do what you did. When you're on the index 2 or 3, and pressed up (Input.trigger?), the above window becomes active. The reason:
@item_window is being updated, which means as soon as you press up, item window will be updated first,
then our code for window switching will be run, by which time, the index is already 0 or 1 in the item window. To fix this, you somehow need to execute your code before the item window is updated. Here's what you try. Remove the item window updating from the update method, and add it to update_item method, after the window-switching code. I'll try it and tell you the result.
EDIT3:
Yup, works :D
So that's it, you need to do the window-switching before updating the item window.
I "tried" with some elses update_cursor_rect method, just to see if it'd do anything. But I took it out again since the standard one works just as well/poorly.
Here is the update method for the other window, if that's any help:
def update_key
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Menu2.new(1)
elsif Input.trigger?(Input::C)
$game_system.se_play($data_system.decision_se)
$scene = Scene_Keyitems.new
elsif Input.trigger?(Input::DOWN)
@item_window.active = true
@item_window.index = 0
@keyitemstitle_window.active = false
@keyitemstitle_window.index = -1
end
end
QuoteEDIT3:
Yup, works
So that's it, you need to do the window-switching before updating the item window.
lol! reminds me of the old times in CP when I used to edit my post and get confused :lol:
trying it now, thanks in advance ^_^
wow...thanks very much, this had been bugging me all day. Funny thing actually, I tried moving the update method around a bit because I figured that might be causing it. It wasn't until you said to put it after the window-switching that it hit me that that was virtually the only place I HADN'T put it XD
No problem ^_^
And yeah, you might want to remove that update_cursor_rect code, it's not needed.
Way ahead of you there, I took it out as soon as I noticed that a different version of the method did absolutely nothing for me
lol, okay :)
So unless you're busy, tell me this. How far are you into scripting? will you be posting something soon in the scripts section?
At the moment I'm concentrating mainly on CMSes, just because I want to actually finish this menu system. I dont have a huge amount of knowledge about the inbuilt classes in RMXP outside of the window/menu classes, but I know all the basic scripting techniques and I'm pretty good at backtracking through classes and methods to find out how stuff works. One thing I seriously need to work on is the presentation of my scripts (I don't do nearly enough commenting) As well as using aliases.
In short, I've got a lot to learn, but I'm not too bad at what I CAN do :P
I might actually be posting this CMS up if I get the entire thing to work to my liking. Thought it's probably been done before, it'll look very similar to the menus from "Tales of Phantasia" (one of my favorite games....ever).
I'll have to clean up the code by a huge amount though, and make it actually compatible with other stuff :P
I assume you know how to alias. And check out some other scripts online to decide what to comment. I use Blizzard's style mixed with my own. There's one thing you have to check out, Bliz's scripting tute.
http://forum.chaos-project.com/index.php?topic=22.0
yeah, I do know how to alias, I just don't feel the need in my own projects, since I can just change the original scripts for my own purposes. I've got a pretty good idea of what I should comment, I just haven't made it a habbit yet to actually do it, unless it's something I think I would not understand personally when I reread my script. Working on changing my bad habbit though :P
Don;t worry, you'll get used to it once you start posting scripts. It's a 'habit-on-demand', you'll learn it when you need it.
Quoteyeah, I do know how to alias, I just don't feel the need in my own projects, since I can just change the original scripts for my own purposes.
About that, I've thought the same thing until the 'mods' became too many and I got confused. Right now, I have a about 30 new script slots where I've aliased the new features/mods. It's easier to keep track that way once the number of mods increases. That's just my way of doing things though, to each his own :D