Hey guys, I'm having a bit of trouble with menus, and I was hoping that someone could let me know what could be going wrong!
Here is the code
men := open menu(1)
men1 := add menu item(men)
men2 := add menu item(men)
men3 := add menu item(men)
suspend player
set menu item caption(men1, get hero name(1, hero by rank(1)))
set menu item caption(men2, get hero name(1, hero by rank(2)))
set menu item caption(men3, get hero name(1, hero by rank(3)))
set menu item type(men1, menutype:textbox)
set menu item type(men2, menutype:textbox)
set menu item type(men3, menutype:textbox)
set menu item subtype(men1, (hero by rank(1)+2)*1000)
set menu item subtype(men2, (hero by rank(2)+2)*1000)
set menu item subtype(men3, (hero by rank(3)+2)*1000)
set menu item bit(men1, menu item bit:Close menu when selected)
set menu item bit(men2, menu item bit:Close menu when selected)
set menu item bit(men3, menu item bit:Close menu when selected)
resume player
So, the idea is the menu lists the names of the Heroes in slots 1-3, then you choose the option and the corresponding textbox appears.
The issue is, the names appear in a seemingly random, often incorrect order. However, the TEXTBOXES appear correctly per hero slot, (NOT per menu slot).
As an example, the ACTUAL order of my party could be:
A
B
C
The menu brings up:
B
A
C
The textboxes brought up, however, are:
A
B
C
Thanks in advance for the help!
Menu trouble
Moderators: marionline, SDHawk
Menu trouble
You can't fix stupidity.
- Bob the Hamster
- Lord of the Slimes
- Posts: 7660
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
"get hero name" is being used wrong in two different ways.
Here is the correct way to do it:
First, Mogri is correct, "get hero name" does *not* return a string id, it returns true for success and false for failure. By lucky coincidence, you happen to be using string id 1, and true is equal to 1, so because of that fluke your code sort-of-worked.
Second, "get hero name" expects the hero's position in the caterpillar party, but "hero by rank" returns the hero's ID number.
I suggest reading: http://rpg.hamsterrepublic.com/ohrrpgce ... n_a_script which explains the three different ways to refer to heroes, and how to convert in between them
Also, two minor details.
"suspend player" and "resume player" do absolutely nothing in this script, because there are no "wait" commands, so no time passes in which the player could do anything.
This script is perfect for a "for" loop. Here is an example of how it would look:
Here is the correct way to do it:
Code: Select all
get hero name(1, find hero(hero by rank(slot)))
set menu item caption(mi, 1)
Second, "get hero name" expects the hero's position in the caterpillar party, but "hero by rank" returns the hero's ID number.
I suggest reading: http://rpg.hamsterrepublic.com/ohrrpgce ... n_a_script which explains the three different ways to refer to heroes, and how to convert in between them
Also, two minor details.
"suspend player" and "resume player" do absolutely nothing in this script, because there are no "wait" commands, so no time passes in which the player could do anything.
This script is perfect for a "for" loop. Here is an example of how it would look:
Code: Select all
script, hero name menu, begin
variable(men, mi, slot)
men := open menu(1)
for(slot, 1, 3) do(
mi := add menu item(men)
get hero name(1, find hero(hero by rank(slot)))
set menu item caption(mi, 1)
set menu item type(mi, menutype:textbox)
set menu item subtype(mi, (hero by rank(slot)+2)*1000)
set menu item bit(mi, menu item bit:Close menu when selected)
)
end
Ugh! I never realised that the "get * name" commands returned true on success (meaning you didn't pass invalid arguments). Not only is it undocumented, it's also unfortunate, as in future once we have real string I wanted to change those commands to return a string, and make the string id argument optional. I guess I can still do that though.Bob the Hamster wrote:First, Mogri is correct, "get hero name" does *not* return a string id, it returns true for success and false for failure. By lucky coincidence, you happen to be using string id 1, and true is equal to 1, so because of that fluke your code sort-of-worked.
Typo! "get hero name" expects a party slot number, not caterpillar position (rank)Second, "get hero name" expects the hero's position in the caterpillar party, but "hero by rank" returns the hero's ID number.
- Bob the Hamster
- Lord of the Slimes
- Posts: 7660
- Joined: Tue Oct 16, 2007 2:34 pm
- Location: Hamster Republic (Ontario Enclave)
- Contact:
I wonder if we could change the "get * name" commands return values now? The invalid/valid arguments return value is pretty useless now that we have decent error reporting for those things.
I imagine that very few (if any?) games currently check those return values. Is that something that rpgbatch could tell us?
I imagine that very few (if any?) games currently check those return values. Is that something that rpgbatch could tell us?