- 288
- Posts
- 6
- Years
- Seen Feb 3, 2025
Although not technically an error, I have stumbled upon what seems to be an infinite loop, but I'm not sure. When playtesting, after attempting to initiate a trainer battle (doesn't matter which trainer), it says the script took too long to load. I have made a couple of edits to the pbLoadTrainer method in the script section titled PTrainer_NPCTrainers, but am unsure as to why they would be causing problems. Maybe I changed something else that caused this. I think I've deduced the problem to be in the loop with the starting line "for poke in trainer[3]" after placing statements that would cause an error to check where the code would get caught. It will catch the error statement when placed right before the end of this loop but wont reach it if placed before the line "success=true". It is important to note that in this section, I changed the first line to be a conditional statement, making an optional setting with game switch 61 to randomly generate the Pokemon species. When this switch is on and the species is randomly generated, and the trainer battles occur fine. However, when the switch is off, that's where the problems happen. Here's the code for the method. Changes to the original method should be in red.
Code:
def pbLoadTrainer(trainerid,trainername,partyid=0)
if trainerid.is_a?(String) || trainerid.is_a?(Symbol)
if !hasConst?(PBTrainers,trainerid)
raise _INTL("Trainer type does not exist ({1}, {2}, ID {3})",trainerid,trainername,partyid)
end
trainerid=getID(PBTrainers,trainerid)
end
success=false
items=[]
party=[]
opponent=nil
trainers=load_data("Data/trainers.dat")
for trainer in trainers
name=trainer[1]
thistrainerid=trainer[0]
thispartyid=trainer[4]
next if trainerid!=thistrainerid || name!=trainername || partyid!=thispartyid
items=trainer[2].clone
name=pbGetMessageFromHash(MessageTypes::TrainerNames,name)
for i in RIVALNAMES
if isConst?(trainerid,PBTrainers,i[0]) && $game_variables[i[1]]!=0
name=$game_variables[i[1]]
end
end
opponent=PokeBattle_Trainer.new(name,thistrainerid)
opponent.setForeignID($Trainer) if $Trainer
for poke in trainer[3]
[COLOR="Red"]if !$game_switches[61]
species=poke[TPSPECIES]
else
species=1+rand(PBSpecies.maxValue)
end[/COLOR]
level=poke[TPLEVEL]
pokemon=PokeBattle_Pokemon.new(species,level,opponent)
pokemon.forcedForm = true if poke[TPFORM]!=0 && MultipleForms.hasFunction?(pokemon.species,"getForm")
pokemon.formNoCall=poke[TPFORM]
pokemon.trainerResetMoves
pokemon.setItem(poke[TPITEM])
if poke[TPMOVE1]>0 || poke[TPMOVE2]>0 || poke[TPMOVE3]>0 || poke[TPMOVE4]>0
k=0
for move in [TPMOVE1,TPMOVE2,TPMOVE3,TPMOVE4]
pokemon.moves[k]=PBMove.new(poke[move])
k+=1
end
pokemon.moves.compact!
end
pokemon.setAbility(poke[TPABILITY])
pokemon.setGender(poke[TPGENDER])
[COLOR="red"]trainerShiny=rand(65535)
if poke[TPSHINY] || trainerShiny<655 # if this is a shiny Pokémon
pokemon.makeShiny
else
pokemon.makeNotShiny
end[/COLOR]
pokemon.setNature(poke[TPNATURE])
iv=poke[TPIV]
for i in 0...6
pokemon.iv[i]=iv&0x1F
pokemon.ev[i]=[85,level*3/2].min
end
pokemon.happiness=poke[TPHAPPINESS]
pokemon.name=poke[TPNAME] if poke[TPNAME] && poke[TPNAME]!=""
if poke[TPSHADOW] # if this is a Shadow Pokémon
pokemon.makeShadow rescue nil
pokemon.pbUpdateShadowMoves(true) rescue nil
pokemon.makeNotShiny
end
pokemon.ballused=poke[TPBALL]
pokemon.calcStats
party.push(pokemon)
end
success=true
break
end
return success ? [opponent,items,party] : nil
end