Advertiser Content

Vendily

Female
Seen 16 Hours Ago
Posted 6 Days Ago
914 posts
4 Years
[RESOLVED]

So, I've made some custom code for Essentials BW 3.1.1, which is very loosely based of the MysteryGift code.
The first function, pbSaveImport, is supposed to take a file, extract the string, convert it into a pokemon, and clear the file.
Another function, pbMenuExport, is supposed to take a pokemon, convert it into a long string, and save it into that file.
But. I've been getting this error, and I can't track it down in the code.
Exception: ArgumentError
Message: The species number (no. 0 of 650) is invalid.
PokeBattle_Pokemon:861:in `__mf_initialize'
Pokemon_MultipleForms:114:in `initialize'
ExportImport:70:in `new'
ExportImport:70:in `pbSaveImport'
Debug:857:in `pbDebugMenu'
Debug:300:in `loop'
Debug:862:in `pbDebugMenu'
Debug:996:in `main'
Main:54:in `mainFunctionDebug'
Main:26:in `mainFunction'
I'm almost positive it's not the extraction because when I change it to the next value, the personal ID, I got the same error but with the ID instead.
Exception: ArgumentError
Message: The species number (no. 3547729879 of 650) is invalid.
PokeBattle_Pokemon:861:in `__mf_initialize'
Pokemon_MultipleForms:114:in `initialize'
ExportImport:70:in `new'
ExportImport:70:in `pbSaveImport'
Debug:855:in `pbDebugMenu'
Debug:300:in `loop'
Debug:862:in `pbDebugMenu'
Debug:996:in `main'
Main:54:in `mainFunctionDebug'
Main:26:in `mainFunction'
Code
Spoiler:
def pbSaveImport
  gift=""
  if safeExists?("ExportImportBW.txt")
    File.open("ExportImportBW.txt") { |f|
      f.each_line { |line| gift += line }
    }
  else
    return nil
  end
  t=gift.split(']//sp//]')

  iv1 = t[1]
  iv2 = t[2]
  iv3 = t[3]
  iv4 = t[4]
  iv5 = t[5]
  iv6 = t[6]
  ev1 = t[7]
  ev2 = t[8]
  ev3 = t[9]
  ev4 = t[10]
  ev5 = t[11]
  ev6 = t[12]
  species = t[13]
  pid = t[14]
  tid = t[15]
  pokerus = t[16]
  item = t[17]
  mail = t[18]
  nickname = t[19]
  exp = t[20]
  happiness = t[21]
  status = t[22]
  statusCount = t[23]
  eggsteps = t[24]

  move1 = t[25].to_s.split('*')
  move2 = t[26].to_s.split('*')
  move3 = t[27].to_s.split('*')
  move4 = t[28].to_s.split('*')
  firstmove1 = t[29]
  firstmove2 = t[30]
  firstmove3 = t[31]
  firstmove4 = t[32]
  ballused = t[33]
  obtainMode = t[34]
  obtainMap = t[35]
  if t[0] != GAMEID
    obtainText = "A faraway region"
  else
    obtainText = t[36]
  end
  obtainLevel = t[37]
  hatchedMap = t[38]
  language = t[39]
  ot = t[40]
  otgender = t[41]
  abilityflag = t[42]
  genderflag = t[43]
  natureflag = t[44]
  shinyflag = t[45]
  ribbons = t[46]
  obtainDay = t[47]
  obtainMonth = t[48]
  obtainYear = t[49]
  customAbility = t[50]
  level = t[51]
  form = t[52]
  
  pokemon=PokeBattle_Pokemon.new(species.to_i,level.to_i,nil,false)
  
  pokemon.iv[0]=iv1.to_i  
  pokemon.iv[1]=iv2.to_i
  pokemon.iv[2]=iv3.to_i
  pokemon.iv[3]=iv4.to_i
  pokemon.iv[4]=iv5.to_i
  pokemon.iv[5]=iv6.to_i
  
  pokemon.ev[0]=ev1.to_i  
  pokemon.ev[1]=ev2.to_i
  pokemon.ev[2]=ev3.to_i
  pokemon.ev[3]=ev4.to_i
  pokemon.ev[4]=ev5.to_i
  pokemon.ev[5]=ev6.to_i
  
  pokemon.personalID=pid.to_i
  pokemon.pokerus=pokerus.to_i
  pokemon.item=item.to_i
  pokemon.mail=mail
  pokemon.name=nickname.to_s
  pokemon.exp = exp.to_i
  pokemon.happiness = happiness.to_i
  pokemon.status = status
  pokemon.statusCount = statusCount
  pokemon.eggsteps = eggsteps.to_i
  
  if move1[0].to_i!=0
    pokemon.moves[0] = PBMove.new(move1[0].to_i)
    pokemon.moves[0].pp = move1[1].to_i
    pokemon.moves[0].ppup = move1[2].to_i
  end
  if move2[0].to_i!=0
    pokemon.moves[1] = PBMove.new(move2[0].to_i)
    pokemon.moves[1].pp = move2[1].to_i
    pokemon.moves[1].ppup = move2[2].to_i
  end
  if move3[0].to_i!=0
    pokemon.moves[2] = PBMove.new(move3[0].to_i)
    pokemon.moves[2].pp = move3[1].to_i
    pokemon.moves[2].ppup = move3[2].to_i
  end
  if move4[0].to_i!=0
    pokemon.moves[3] = PBMove.new(move4[0].to_i)
    pokemon.moves[3].pp = move4[1].to_i
    pokemon.moves[3].ppup = move4[2].to_i
  end
  
  pokemon.firstmoves=[]
  pokemon.firstmoves.push(firstmove1.to_i) if firstmove1.to_i > 0
  pokemon.firstmoves.push(firstmove2.to_i) if firstmove2.to_i > 0
  pokemon.firstmoves.push(firstmove3.to_i) if firstmove3.to_i > 0
  pokemon.firstmoves.push(firstmove4.to_i) if firstmove3.to_i > 0
  
  pokemon.ballused = ballused.to_i
  pokemon.obtainMode = obtainMode.to_i
  pokemon.obtainMap = obtainMap.to_i
  pokemon.obtainText = obtainText.to_s
  pokemon.obtainLevel = obtainLevel.to_i
  pokemon.hatchedMap = hatchedMap.to_i
  pokemon.language = language.to_i
  
  pokemon.ot         =   ot.to_s
  pokemon.trainerID  =   tid.to_i
  pokemon.otgender   =   otgender.to_i
  
  pokemon.abilityflag = abilityflag.to_i
  pokemon.genderflag = genderflag.to_i
  pokemon.natureflag = natureflag.to_i
  pokemon.shinyflag = eval(shinyflag)
  pokemon.ribbons = ribbons
  pokemon.obtainDay = obtainDay.to_i
  pokemon.obtainMonth = obtainMonth.to_i
  pokemon.obtainYear = obtainYear.to_i
  pokemon.customAbility = customAbility.to_i
  
  if form != ""
    pokemon.form = form.to_i
  else
    pokemon.form = 0
  end
  
  pokemon.calcStats
  begin
      File.open("ExportImportBW.txt","wb"){|f|
      f.write("")
      }
  end
  return pokemon
end

def pbMenuExport(pokemon=nil)
  if pokemon != nil
    exportedPoke=""
    if safeExists?("ExportImportBW.txt")
      File.open("ExportImportBW.txt") { |f|
      f.each_line { |line| exportedPoke += line }
      }
    end
   
    iv1=pokemon.iv[0]
    iv2=pokemon.iv[1]
    iv3=pokemon.iv[2]
    iv4=pokemon.iv[3]
    iv5=pokemon.iv[4]
    iv6=pokemon.iv[5]
    ev1=pokemon.ev[0]
    ev2=pokemon.ev[1]
    ev3=pokemon.ev[2]
    ev4=pokemon.ev[3]
    ev5=pokemon.ev[4]
    ev6=pokemon.ev[5]
    species=pokemon.species
    pid=pokemon.personalID
    tid=pokemon.trainerID
    pokerus=pokemon.pokerus
    item=pokemon.item
    mail=pokemon.mail
    nickname=pokemon.name
    exp=pokemon.exp
    happiness=pokemon.happiness
    status=pokemon.status
    statusCount=pokemon.statusCount
    eggsteps=pokemon.eggsteps
    
    move1id=pokemon.moves[0].id
    move2id=pokemon.moves[1].id
    move3id=pokemon.moves[2].id
    move4id=pokemon.moves[3].id
    move1pp=(pokemon.moves[0].id!=0)? pokemon.moves[0].pp : ""
    move2pp=(pokemon.moves[1].id!=0)? pokemon.moves[1].pp : ""
    move3pp=(pokemon.moves[2].id!=0)? pokemon.moves[2].pp : ""
    move4pp=(pokemon.moves[3].id!=0)? pokemon.moves[3].pp : ""
    move1ppup=(pokemon.moves[0].id!=0)? pokemon.moves[0].ppup : ""
    move2ppup=(pokemon.moves[1].id!=0)? pokemon.moves[1].ppup : ""
    move3ppup=(pokemon.moves[2].id!=0)? pokemon.moves[2].ppup : ""
    move4ppup=(pokemon.moves[3].id!=0)? pokemon.moves[3].ppup : ""
    
    firstmove1=pokemon.firstmoves[0]
    firstmove2=pokemon.firstmoves[1]
    firstmove3=pokemon.firstmoves[2]
    firstmove4=pokemon.firstmoves[3]
    
    ballused=pokemon.ballused
    obtainMode=pokemon.obtainMode
    
    obtainMap=pokemon.obtainMap
    obtainText=pokemon.obtainText
    obtainLevel=pokemon.obtainLevel
    hatchedMap=pokemon.hatchedMap
    language=pokemon.language
    ot=pokemon.ot
    otgender=pokemon.otgender
           
    abilityflag=pokemon.abilityflag
    genderflag=pokemon.genderflag
    natureflag=pokemon.natureflag
    shinyflag=pokemon.shinyflag
    ribbons=pokemon.ribbons
       
    obtainDay=pokemon.obtainDay
    obtainMonth=pokemon.obtainMonth
    obtainYear=pokemon.obtainYear
   
    customAbility=pokemon.customAbility
    level=pokemon.level
    form=pokemon.form
    
    gameid=GAMEID
    exportedPoke=sprintf("#{gameid}]//sp//]#{iv1}]//sp//]#{iv2}]//sp//]#{iv3}]//sp//]#{iv4}]//sp//]#{iv5}]//sp//]#{iv6}]//sp//]#{ev1}]//sp//]#{ev2}]//sp//]#{ev3}]//sp//]#{ev4}]//sp//]#{ev5}]//sp//]#{ev6}]//sp//]#{species}]//sp//]#{pid}]//sp//]#{tid}]//sp//]#{pokerus}]//sp//]#{item}]//sp//]#{mail}]//sp//]#{nickname}]//sp//]#{exp}]//sp//]#{happiness}]//sp//]#{status}]//sp//]#{statusCount}]//sp//]#{eggsteps}]//sp//]#{move1id}*#{move1pp}*#{move1ppup}]//sp//]#{move2id}*#{move2pp}*#{move2ppup}]//sp//]#{move3id}*#{move3pp}*#{move3ppup}]//sp//]#{move4id}*#{move4pp}*#{move4ppup}]//sp//]#{firstmove1}]//sp//]#{firstmove2}]//sp//]#{firstmove3}]//sp//]#{firstmove4}]//sp//]#{ballused}]//sp//]#{obtainMode}]//sp//]#{obtainMap}]//sp//]#{obtainText}]//sp//]#{obtainLevel}]//sp//]#{hatchedMap}]//sp//]#{language}]//sp//]#{ot}]//sp//]#{otgender}]//sp//]#{abilityflag}]//sp//]#{genderflag}]//sp//]#{natureflag}]//sp//]#{shinyflag}]//sp//]#{ribbons}]//sp//]#{obtainDay}]//sp//]#{obtainMonth}]//sp//]#{obtainYear}]//sp//]#{customAbility}]//sp//]#{level}]//sp//]#{form}")
    begin
      File.open("ExportImportBW.txt","wb"){|f|
      f.write(exportedPoke)
      }
    end
  end
end
Example Exported Pokemon (Level 10 Magikarp from a male trainer named Example)
MEW]//sp//]17]//sp//]2]//sp//]19]//sp//]28]//sp//]0]//sp//]16]//sp//]0]//sp//]0]//sp//]0]//sp//]0]//sp//]0]//sp//]0]//sp//]129]//sp//]1561824254]//sp//]195063392]//sp//]]//sp//]0]//sp//]]//sp//]Magikarp]//sp//]1250]//sp//]70]//sp//]0]//sp//]0]//sp//]0]//sp//]410*40*0]//sp//]0**]//sp//]0**]//sp//]0**]//sp//]410]//sp//]]//sp//]]//sp//]]//sp//]0]//sp//]0]//sp//]33]//sp//]]//sp//]10]//sp//]0]//sp//]2]//sp//]Example]//sp//]0]//sp//]]//sp//]]//sp//]]//sp//]]//sp//]]//sp//]3]//sp//]9]//sp//]2016]//sp//]]//sp//]10]//sp//]0


Thank you in advanced for any help. (It's probably something really small and stupid.)

EDIT: For what it's worth, the issue seems to be passing the values to the Initialization because hardcoding the species gave me this error for the level.
Exception: ArgumentError
Message: The level number (0) is invalid.
PokeBattle_Pokemon:131:in `level='
PokeBattle_Pokemon:906:in `__mf_initialize'
Pokemon_MultipleForms:114:in `initialize'
ExportImport:70:in `new'
ExportImport:70:in `pbSaveImport'
Debug:857:in `pbDebugMenu'
Debug:300:in `loop'
Debug:862:in `pbDebugMenu'
Debug:996:in `main'
Main:54:in `mainFunctionDebug'

☆Rei☆

Age 22
Female
Nearby my feet.
Seen 5 Days Ago
Posted November 21st, 2018
1,748 posts
10 Years
You're trying to turn a string "MEW" into an integer. Ruby doesn't know that "MEW" (in string format) is the same as "150"


Edit:

It appears as if that was actually not the case. I made an assumption without looking at the code. I will look further into it.

Vendily

Female
Seen 16 Hours Ago
Posted 6 Days Ago
914 posts
4 Years
You're trying to turn a string "MEW" into an integer. Ruby doesn't know that "MEW" (in string format) is the same as "150"
That is not what I'm doing. The Initial MEW is the game's id, for cross-game trading (If I ever use it). My example export is a Magikarp and is the bolded section.
MEW]//sp//]17]//sp//]2]//sp//]19]//sp//]28]//sp//]0]//sp//]16]//sp//]0]//sp//]0]//sp//]0]//sp//]0]//sp//]0]//sp//]0]//sp//]129]//sp//]1561824254]//sp//]195063392]//sp//]]//sp//]0]//sp//]]//sp//]Magikarp]//sp//]1250]//sp//]70]//sp//]0]//sp//]0]//sp//]0]//sp//]410*40*0]//sp//]0**]//sp//]0**]//sp//]0**]//sp//]410]//sp//]]//sp//]]//sp//]]//sp//]0]//sp//]0]//sp//]33]//sp//]]//sp//]10]//sp//]0]//sp//]2]//sp//]Example]//sp//]0]//sp//]]//sp//]]//sp//]]//sp//]]//sp//]]//sp//]3]//sp//]9]//sp//]2016]//sp//]]//sp//]10]//sp//]0

☆Rei☆

Age 22
Female
Nearby my feet.
Seen 5 Days Ago
Posted November 21st, 2018
1,748 posts
10 Years
That is not what I'm doing. The Initial MEW is the game's id, for cross-game trading (If I ever use it). My example export is a Magikarp and is the bolded section.
MEW]//sp//]17]//sp//]2]//sp//]19]//sp//]28]//sp//]0]//sp//]16]//sp//]0]//sp//]0]//sp//]0]//sp//]0]//sp//]0]//sp//]0]//sp//]129]//sp//]1561824254]//sp//]195063392]//sp//]]//sp//]0]//sp//]]//sp//]Magikarp]//sp//]1250]//sp//]70]//sp//]0]//sp//]0]//sp//]0]//sp//]410*40*0]//sp//]0**]//sp//]0**]//sp//]0**]//sp//]410]//sp//]]//sp//]]//sp//]]//sp//]0]//sp//]0]//sp//]33]//sp//]]//sp//]10]//sp//]0]//sp//]2]//sp//]Example]//sp//]0]//sp//]]//sp//]]//sp//]]//sp//]]//sp//]]//sp//]3]//sp//]9]//sp//]2016]//sp//]]//sp//]10]//sp//]0

From what I can gather, the script works fine in loading and unloading the Pokemon.

I only get the error when trying to load the Pokemon twice in a row without resetting the text file.

Also, as another note: You left a few fields "status" and "statusCount" as raw strings. As well as "mail" is neither a string nor an integer, so you're going to need to find a way to wrap around that, too.

Otherwise, I think the issue may be because you're trying to load a blank file.


Edit:

Also, do you need it in this format? Why don't you just use the Mystery Gift functions to turn the Pokemon into a string, and vice-versa?

Vendily

Female
Seen 16 Hours Ago
Posted 6 Days Ago
914 posts
4 Years
From what I can gather, the script works fine in loading and unloading the Pokemon.

I only get the error when trying to load the Pokemon twice in a row without resetting the text file.

Also, as another note: You left a few fields "status" and "statusCount" as raw strings. As well as "mail" is neither a string nor an integer, so you're going to need to find a way to wrap around that, too.

Otherwise, I think the issue may be because you're trying to load a blank file.


Edit:

Also, do you need it in this format? Why don't you just use the Mystery Gift functions to turn the Pokemon into a string, and vice-versa?
Oh my god, I love you. I found the problem was when I overwrote the file. Taking that out fixed it. (Kind of, crashed on opening the party screen but this was what was bothering me.)
And I didn't just use the Mystery Gift functions because the one that comes with Essentials BW is limited and effectively creates a new pokemon with new stats, because of not setting stuff like PID, while I plan to use this as a trading system, and need all the attributes to be saved

☆Rei☆

Age 22
Female
Nearby my feet.
Seen 5 Days Ago
Posted November 21st, 2018
1,748 posts
10 Years
Oh my god, I love you. I found the problem was when I overwrote the file. Taking that out fixed it. (Kind of, crashed on opening the party screen but this was what was bothering me.)
That's why I told you to fix the "status" and "statusCount" variables.
Also, the input for the "mail" variable needs to be a form of "PokemonMail" otherwise it will also crash when looking at the Summary.

And I didn't just use the Mystery Gift functions because the one that comes with Essentials BW is limited and effectively creates a new pokemon with new stats, because of not setting stuff like PID, while I plan to use this as a trading system, and need all the attributes to be saved
Well, you could use these functions instead:

def pbPokemonToString(gift)
  ret=[Zlib::Deflate.deflate(Marshal.dump(gift))].pack("m")
  return ret
end

def pbStringToPokemon(gift)
  return [] if gift==""
  ret=Marshal.restore(Zlib::Inflate.inflate(gift.unpack("m")[0]))
  return ret
end
Which is basically found in the core Pokemon Essentials' Mystery Gift functions. (But renamed to be more appropriate in your case)

And by chance this will also fix all your other issues, while making it more easy on your part if you happen to change the structure of the PokeBattle_Pokemon class.
Advertiser Content