Menu trouble

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
ncw64
Slime Knight
Posts: 223
Joined: Mon Jun 21, 2010 4:11 am
Location: Edinboro, PA

Menu trouble

Post by ncw64 »

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!
You can't fix stupidity.
User avatar
Mogri
Super Slime
Posts: 4669
Joined: Mon Oct 15, 2007 6:38 pm
Location: Austin, TX
Contact:

Post by Mogri »

hero by rank should take 0-3 as an argument, not 1-4.

Aside: I'm surprised that set menu item caption(men1, get hero name(1, hero by rank(1))) works. Does get hero name return the string ID? If so, that's undocumented.
ncw64
Slime Knight
Posts: 223
Joined: Mon Jun 21, 2010 4:11 am
Location: Edinboro, PA

Post by ncw64 »

I know, but this is for party chat, so I am using indices 1-3 only here.

I do believe the plotscripting dictionary suggests that you can use;
get hero name in order to get a string (and it definitely works in my game).
You can't fix stupidity.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

"get hero name" is being used wrong in two different ways.

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)
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:

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
ncw64
Slime Knight
Posts: 223
Joined: Mon Jun 21, 2010 4:11 am
Location: Edinboro, PA

Post by ncw64 »

Ahhhh gotcha, thank you very much! I see what you mean, and yea. First time trying out the menu scripts, but that makes a lot of sense. Especially with the
for loop.

Thanks again, and I'll remember the find hero vs. hero by rank thing!
You can't fix stupidity.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

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.
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.
Second, "get hero name" expects the hero's position in the caterpillar party, but "hero by rank" returns the hero's ID number.
Typo! "get hero name" expects a party slot number, not caterpillar position (rank)
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

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?
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Yes, I could check that.

The alternative would be to return a string only if you don't pass a string id.
Post Reply