Hi I was wondering if someone could explain some of the terms in the Pokemon Utilities code? I understand things like def and stuff..but here are the commands I don't really understand that are
highlighted in bold:
Code:
def pbChangePlayer(id)
return false if [B]id<0||id>[/B]=4
[B]meta[/B]=pbGetMetadata([B]0,MetadataPlayerA+id[/B])
return false if [B]!meta[/B]
[B]$game_player.character_name=meta[1]
$game_player.character_hue=0
$PokemonGlobal.playerID=id[/B]
end
def pbGetPlayerGraphic
[B]id=$PokemonGlobal.playerID[/B]
return "" if id<0||id>=4
meta=pbGetMetadata(0,MetadataPlayerA+id)
return [B]""[/B] if !meta
return [B]sprintf("../Characters/trainer%03d",meta[0])[/B]
end
def [B]pbGetPlayerTrainerType[/B]
id=$PokemonGlobal.playerID
return 0 if id<0||id>=4
meta=pbGetMetadata(0,MetadataPlayerA+id)
return 0 if !meta
return meta[0]
end
def [B]pbGetTrainerTypeGender(trainertype)[/B]
ret=2
pbRgssOpen[B]("Data/trainernames.dat","rb"){|f|[/B]
[B]trainernames=Marshal.load(f)[/B]
if !trainernames[trainertype]
ret=2
else
[B]ret=trainernames[trainertype][7]
ret=2 if !ret[/B]
end
}
return ret
end
def pbTrainerName
trname=pbEnterText("Your name?",0,10,"Ashley")
trainertype=pbGetPlayerTrainerType
gender=pbGetTrainerTypeGender(trainertype)
if trname==""
trname=getRandomNameEx[B](gender,nil,1)[/B]
end
$Trainer=PokeBattle_Trainer.new(trname,trainertype)
$PokemonBag=PokemonBag.new
$PokemonTemp.begunNewGame=true
end
Sorry if this question is irritating or anything. I read a crash course of Ruby programming language but it seems some of the terms and strings are game exclusively defined only.
OK, here goes.
This means 'if id is less than 0
or id is greater than or equal to 4'.
Code:
meta=pbGetMetadata(0,MetadataPlayerA+id)
This evaluates the pbGetMetadata method, and assigns it to the 'meta' local variable. 'MetadataPlayerA' is a constant; in this case, it's a kind of pointer to where the player information is stored. In this case, it's the second entry in the metadata file (for map 0; i.e. global). 'id' is the id number of the desired player type (given as an argument to the method), and is added to the 'pointer' to get data on a specific player ID.
This means 'not meta'; i.e. it would exit from the method if the 'meta' local variable is nil or false, which would happen if it failed to get the metadata.
$game_player and $PokemonGlobal are global variables (denoted by the $). $game_player is an instance of the Game_Player class, while $PokemonGlobal is likewise an instance of PokemonGlobal.
The sprintf method returns a formatted string. For example, the %03d parameter in the string is replaced by 'meta[0]' (the second argument), with at least 3 digits and padded by zeroes (for example, 003).
I'm not sure why you bolded the method definitions for pbGetPlayerTrainerType and pbGetTrainerTypeGender; care to clarify?
Code:
pbRgssOpen("Data/trainernames.dat","rb"){|f|
trainernames=Marshal.load(f)
Anyway, pbRgssOpen is a method poccil wrote to be used instead of File.open. This is because File.open doesn't work with files in an RGSS encrypted archive. The first argument is the file to be opened, and the second is how it should be opened ('rb' means it should be opened in binary read mode). '{|f|' starts a block, and assigns the 'f' variable to the file opened. It's a different way to write 'f=pbRgssOpen'; however, when a block is used, the 'f' variable cannot be used outside it unless it's defined first.
Marshal.load is a Ruby method of loading an object from a file; in this case, it loads an Array object. It's the opposite of Marshal.dump.
Code:
ret=trainernames[trainertype][7]
ret=2 if !ret
This just assigns the ret variable to an element of a two-dimensional array (i.e. an array where each element is another array). If the element doesn't exist, 2 is assigned instead (in this case, 2 means genderless).
Code:
getRandomNameEx(gender,nil,1)
This calls the getRandomNameEx method. The arguments for this are (in order) gender, variable to be saved to, and capitalization state. In this case, it would be the player's gender, no variable to be saved to, and first letter capitalized only.
All these are actually available in standard Ruby; the only new classes in RGSS are the ones relating to game-only things (such as Bitmap or Sprite). May I suggest you have a look at
this guide? It has a tutorial, but more importantly, contains information on every class and method in standard Ruby. The RGSS-only classes are documented in RMXP's help file.