You are not logged in.
Pages: 1
I am working on some code that randomizes pokemon per-encounter instead of hard coding the slots like the universal randomizer. So far I have it working to the point where I DO get random encounters, at the correct levels for the area, but I still get glitch pokemon. I set it to re-randomize when it gets a number larger than 0xBE to avoid getting trainers and such, and I can specifically get it to not choose 0x00 with the following
cp $0
jr z, .GenRandomSpecies
obviously, I have the entire function labeled .GenRandomSpecies
Now, if I add under that
cp $1F
jr z, .GenRandomSpecies
with 1F being the next invalid ID, it works fine. As soon as I add any others, the next being $20 though, I get the following
error: engine/battle/wild_encounters.asm(line_number) : Value must be 8-bit
make: ***[Makefile:52: pokered.gbc] Error 1
the line_number seems to sometimes be the line of the last jr instruction and sometimes it seems completely random like in the case of having just $0, $1F, and $20 it says line 23 which is normally just fine. (not to mention, untouched) or just another random line. I'm attempting to do this for 39 values, but I can't even get past 3. What could cause this?
Last edited by Mallos31 (2018-12-28 00:46:50)
Offline
The jr instruction is an optimized short jump. It stores the jump distance in a single 8-bit byte, instead of a whole two-byte destination. Thus it can only go backwards or forwards ±127 bytes in ROM. If the destination label is farther than that, you have to use jp.
My projects on GitHub:
• Polished Map 4.7.1 or 2.7.1++
• Tilemap Studio 4.0.1
• Pokémon Polished Crystal 2.2.0 or 3.0.0 beta
• Pokémon Red★/Blue★: Space World Edition 2020-11-01
Offline
Fantastic! I'll give it a shot! Thank you very much.
EDIT: Gave it a shot, and it works perfectly! Now's where I take what I've learned and try to hijack trainer roster data and randomize that. Thanks again!
Last edited by Mallos31 (2018-12-30 23:35:31)
Offline
Instead of comparing to all the invalid index values, I would generate a random value from 1 to 151, and then use the routine PokedexToIndex to get the valid index number for the chosen Pokemon
.GenRandomSpecies
call Random
cp NUM_POKEMON + 1
jr nc, .GenRandomSpecies ; too big, invalid
and a
jr z, .GenRandomSpecies ; zero, invalid
ld [wd11e], a
callab PokedexToIndex
ld a, [wd11e]
ret ; return valid index in a
That being said, it's still impressive and valuable to have been able to figure out how to get it to work the way you did
Offline
Pages: 1