rename hero after swapping heros?

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

Moderators: marionline, SDHawk

Post Reply
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

rename hero after swapping heros?

Post by marionline »

Hello,
somehow my script does not ask to name the newly swapped hero.
And I've no idea why. :???:
Could it be that the hero swapping is not noticed by the engine
or is there a mistake in my script that I just fail to see?
Me refers to the first hero in the team, right?
And that would be Mamoruko after swapping places, right?

Code: Select all

plotscript, aaa_test, begin
    add hero (hero:Mamoruko Yamada)
    swap by name (hero:Mamoruko Yamada, hero:Mamoru Yamada)
    delete hero(hero:Mamoru Yamada)
    rename hero(me)
    lock hero (hero:Mamoruko Yamada)
end
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

No, the argument to renamehero should be the hero ID: "rename hero (hero:Mamoruko Yamada)". (If you have multiple copies that that hero in the party, it renames the first one).
"me" is a constant with the value zero. Using it is no different to writing 0.

I usually double-check the documentation for hero commands, because it's very easy to pass the wrong argument. There are three types of commands: ones that use hero IDs, ones that use party positions (from "find hero"), and ones that use caterpillar positions. "me" only makes sense as a caterpillar position.
Last edited by TMC on Thu Jul 06, 2017 9:48 am, edited 2 times in total.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Thanks a lot for the expaination! :)
I wasn't fully aware of the different methods to refer to heroes.
I added "hero by slot(0)" to find the first hero. It works.

(If the player renames it, does the hero keep it's name in the engine?
Could I still use hero:Mamoru if someone called him Peter?)

Code: Select all

plotscript, aaa_test, begin
    add hero (hero:Mamoruko Yamada)
    swap by name (hero:Mamoru Yamada, hero:Mamoruko Yamada )
    delete hero(hero:Mamoru Yamada)
#    rename hero (hero:Mamoruko Yamada)
    rename hero(hero by slot (0)) 
    lock hero (hero:Mamoruko Yamada)
end
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

It only renames them for the current gameplay. All scripts still use hero:OriginalHeroName which is a constant equal to the hero's ID number.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Actually, "rename hero(hero by slot (0))" is still wrong, although it will usually work. It doesn't work if the leader of the party isn't in slot 0, which might happen if you let the player access the Order/Team menu, or if you don't carefully swap a hero into slot 0 when you change the heroes in the party (your script appears to do that).

Instead, write "rename hero(leader)". 'leader' searches for the first party slot with a hero in it (which might be 0, 1, 2, or 3) and returns the ID of that hero.
Last edited by TMC on Sun Jul 09, 2017 2:35 am, edited 1 time in total.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Thanks. :)
I'm a bit confused.What is the correct way to get the name of a hero by it's position?
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

marionline wrote:Thanks. :)
I'm a bit confused.What is the correct way to get the name of a hero by it's position?
The "rename hero" does not care where the hero is in the party, it only cares about their ID number. it will search for the hero no matter where they are currently located in the party.

You might also want to see the "rename hero by slot" command, which expects a party slot number, rather than a hero ID

If you haven't seen it before, you should read this article: http://rpg.hamsterrepublic.com/ohrrpgce ... n_a_script
Last edited by Bob the Hamster on Sun Jul 09, 2017 6:28 pm, edited 1 time in total.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Thanks. :)
The article is good, especially with all those images! :o
I'll correct the script.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Seems like I broke the script when I changed something.
Is there a way to move a hero into a certain slot (of the party and walkabout rank)?

Code: Select all

plotscript, play_as_girl, begin
    add hero (hero:Mamoruko Yamada)
    swap by name (hero:Mamoruko Yamada, hero:Mamoru Yamada)
    delete hero(hero:Mamoru Yamada)
    #rename hero(hero by slot (0))
    lock hero (hero:Mamoruko Yamada) 
    
    if (hero by slot(1)) then(delete hero( hero:Mamoruko Yamada))
    
    # TODO: swap door link from empty room and Mamoru's room!
    # TODO: Alter string variables! 
end
For a reason the girl hero would be added to the team 2 times.
Now the renaming (it happens in another script) does not work:

Code: Select all

show textbox(652) # HINT: This time you have to type an answer.
wait for textbox
wait(4)
rename hero(hero by slot (0)) 
wait(4)
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

"if (hero by slot(1)) then(delete hero( hero:Mamoruko Yamada))" is wrong. hero by slot returns -1 if there is no hero in that slot, because hero IDs count upwards from 0.
And that line doesn't make any sense anyway. Why are you deleting a hero immediately after adding it? I can't tell what your intention was.

As I said before, "rename hero(hero by slot (0))" won't work if there is no hero in the first slot. If you want to rename the first hero, write "rename hero(leader)"
Last edited by TMC on Mon Jul 17, 2017 12:00 am, edited 1 time in total.
User avatar
marionline
Metal Slime
Posts: 673
Joined: Sat Feb 26, 2011 9:23 pm

Post by marionline »

Sorry, forgot about the "rename hero(Leader)" part.

The girl hero is added twice to the party. That's one too much.
But I can't figure out why and when there gets a second hero in the party.

I guess, I'll make use of the swap hero script you wrote in the other thread.
Maybe I can find the mistake, if I compare what I wrote with your script.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Then you must be calling the script twice. What triggers it?

You could try using script logging to find out what's triggering it. You can turn on logging in the debug menu.
Post Reply