The PokéCommunity Forums

The PokéCommunity Forums (https://www.pokecommunity.com/index.php)
-   Binary ROM Hacking (https://www.pokecommunity.com/forumdisplay.php?f=284)
-   -   Script FR - Counting how many gym badges the player currently has? (https://www.pokecommunity.com/showthread.php?t=414928)

frabulator November 3rd, 2018 7:01 AM

FR - Counting how many gym badges the player currently has?
 
Is there a way to count how many gym badges the player currently has in Fire Red? I have looking into the script of the vicotry road guards and found the flags for (I assume) the badges. How would I generate a counter that counts if the player has, say, badge 1 and badge 5, and then does something because the user has 2 badges?

Code:

#org 0x1A796E
textcolor 0x0
applymovement 0x8009 0x81A75E7
waitmovement 0x0
copyvar 0x8000 0x4001
compare 0x8000 0x1
if 0x1 goto 0x81A79D8
compare 0x8000 0x2
if 0x1 goto 0x81A79E7a
compare 0x8000 0x3
if 0x1 goto 0x81A79F6
compare 0x8000 0x4
if 0x1 goto 0x81A7A05
compare 0x8000 0x5
if 0x1 goto 0x81A7A14
compare 0x8000 0x6
if 0x1 goto 0x81A7A23
compare 0x8000 0x7
if 0x1 goto 0x81A7A32
compare 0x8000 0x8
if 0x1 goto 0x81A7A41
end



PITink November 3rd, 2018 7:47 AM

I don't have many experience with variables in Pokémon Scripts, but in theory it should work if you add +1 to a variable after each gym battle. Then just check the variable's value with the new script and continue the script how you want it to be.
I can't tell you much about it, but I hope I could help though

frabulator November 3rd, 2018 8:39 AM

Quote:

Originally Posted by PITink (Post 9944190)
I don't have many experience with variables in Pokémon Scripts, but in theory it should work if you add +1 to a variable after each gym battle. Then just check the variable's value with the new script and continue the script how you want it to be.
I can't tell you much about it, but I hope I could help though

Thats what I was thinking as well, however I do not know how to create a variable in pokemon scripts. In VB its easy enough as 'dim vr as variable = 0" and then "vr = vr +1". But in Pokescripts, I'm lost.

Blah November 3rd, 2018 10:09 AM

Quote:

Originally Posted by frabulator (Post 9944200)
Thats what I was thinking as well, however I do not know how to create a variable in pokemon scripts. In VB its easy enough as 'dim vr as variable = 0" and then "vr = vr +1". But in Pokescripts, I'm lost.

Yeah, pokescripting isn't a programming language and you can only use the defined commands. You don't have to declare any variables. They're all global, and all of the non-temporary ones will retain their value through saves. In scripting, to do arithmetic and variable logic, you need to use the scripting commands. So to add or subtract there are specific commands like addvar and subvar that you need to use.


To setup a way to count:
Quote:

setvar 0x8000 0x0 ' set the value of the variable to 0, so we can start counting from 0

checkflag 0xbadge1
if true call @incrementvar
checkflag 0xbadge2
if true call @incrementvar
checkflag 0xbadge3
if true call @incrementvar
...
To check amount of badges earned after you've counted:
Quote:

compare 0x8000 0x1
if 0x1 goto @onebadge
...
Incrementing a variable
Quote:

#org @incrementvar
addvar 0x8000 0x1
return

I would recommend breaking it down into these 3 parts. Because later on, you could just do something like, "call 0xaddress_for_count_badges" and conserve ROM space.

frabulator November 3rd, 2018 12:25 PM

Quote:

Originally Posted by FBI (Post 9944226)
Yeah, pokescripting isn't a programming language and you can only use the defined commands. You don't have to declare any variables. They're all global, and all of the non-temporary ones will retain their value through saves. In scripting, to do arithmetic and variable logic, you need to use the scripting commands. So to add or subtract there are specific commands like addvar and subvar that you need to use.


To setup a way to count:


To check amount of badges earned after you've counted:


Incrementing a variable



I would recommend breaking it down into these 3 parts. Because later on, you could just do something like, "call 0xaddress_for_count_badges" and conserve ROM space.



This is perfect! You rock! Thank you very much!


All times are GMT -8. The time now is 9:14 AM.


Like our Facebook Page Follow us on Twitter © 2002 - 2018 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2016 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.

Acknowledgements
Use of PokéCommunity Assets
vB Optimise by DragonByte Technologies Ltd © 2023.