Page 1 of 1

get hero stat

Posted: Sun Sep 04, 2011 5:16 pm
by Willy Elektrix
You think after having written 3 games, I'd know how to do something simple like this, but I don't.

In my game, I've renamed the Ctr stat to Score. This stat keeps track of the points you've earned from achieving special objectives. At the end of the game, I want to display messages based on what your score is. I did something similar to this on my last game, but this time Score is a hero stat instead of a variable.

How do I make the hero stat Score into a variable I can use in an If statement (example below)?

Code: Select all

if (score == 14)
then, begin
show text box (141)
end

Posted: Sun Sep 04, 2011 7:09 pm
by KF Harlock
You should be able to do it like this:

Code: Select all

variable(scorekeeper)

scorekeeper := getherostat(me, stat:score)

if (scorekeeper == 14), then,
begin
showtextbox(141)
#other stuff
end
I just used "scorekeeper" as the variable name to distinguish it from the name of the "score" stat; you can name it most anything.

Note also that using "me" in getherostat assumes you're counting the score of whatever player is at the first position in your party, to have it specifically target a hero, you'd use "findhero(hero:heroname)" in place of "me".

Posted: Mon Sep 05, 2011 2:24 am
by TMC
Minor nitpick, but note that "getherostat(me, stat:score)" does not return the value of the Score stat for the party leader. getherostat takes a party slot, not a caterpillar party slot, so using 'me' isn't correct if it's possible for the player to rearrange the party (slot 0 might be empty). So yes, using findhero is better, for example "find hero (leader)".

Posted: Mon Sep 05, 2011 6:42 am
by KF Harlock
Thanks, TMC. After all these years, I still get unclear on which commands take party slot, which take caterpillar slot, and which take hero ID... @_@

Posted: Mon Sep 05, 2011 8:22 am
by TMC
It took me years to learn as well! The rule is things related to the on-map walkabouts, except their graphics --- x/y/z position, direction, and speed --- are per-caterpillar party slot. Speed is an odd exception: heroes not in the active party don't have a speed. Nearly everything else acts on hero data, such as sprites, stats, name, spell lists, etc. and takes the party slot. As for hero definition ID, the only things which use it are party manipulation commands such as addhero... and unfortunately also un/lockhero, deletehero, and swapin/outhero which is just plain wrong and broken, because it means these commands don't support parties with multiple copies of the same hero ID. Ideally addhero and findhero (and swapbyname) would be the only commands using a hero ID.

Posted: Mon Sep 05, 2011 3:42 pm
by Willy Elektrix
Thanks for your help Harlock. I got it working.

Posted: Thu Sep 08, 2011 1:08 am
by Willy Elektrix
Howdy. I've got another one. I want to make an menu option that displays a different text box depending on which map you are on.

How would I use the "current map" command to make it into an "if" statement. For instance...

Code: Select all

variablename := current map

if (variablename == 1)
then, begin
show text box (1)
end

if (variablename == 2)
then, begin
show text box (2)
end
Except that's not right since "current map" doesn't really work like that. Any thoughts?

Posted: Thu Sep 08, 2011 1:23 am
by Bob the Hamster
Willy Elektrix wrote: Except that's not right since "current map" doesn't really work like that. Any thoughts?
Actually, yes, current map does work like that.

The script you wrote should work fine. Although you can actually simplify it a bit further and not use a variable:

Code: Select all

if (current map == 1)
then, begin
show text box (1)
end

if (current map == 2)
then, begin
show text box (2)
end