Advertiser Content
Seen 1 Week Ago
Posted 1 Week Ago
51 posts
63 Days
Hello guys(/girls?),

I have an unexpected bug using this script. I wanted to have adapting level for wild bosses and if the one boss is a scizor then teach it the moves. Though now that this works perfectly I suddenly realise that any time the switch all pokemon encountered are Scizors even though they keep their names (for example mewtwo when meeting it or even krabby while walking on the seashore) and they have the moves I wanted Scizor to learn.

I don't understand why this line "if pokemon.species==212" is turning every poke in 212 instead of just checking if it is a scizor or not.

Thank you for your help


if $game_switches[89] and if pbBalancedLevel($Trainer.party)>1     
     newlevel=pbBalancedLevel($Trainer.party) + 1 
      if pbBalancedLevel($Trainer.party)>10
        newlevel=pbBalancedLevel($Trainer.party) + 2        
      end  
      if pbBalancedLevel($Trainer.party)>20
        newlevel=pbBalancedLevel($Trainer.party) + 4        
      end  
      if pbBalancedLevel($Trainer.party)>30
        newlevel=pbBalancedLevel($Trainer.party) + 6       
      end  
      if pbBalancedLevel($Trainer.party)>40
        newlevel=pbBalancedLevel($Trainer.party) + 8       
      end  
      if pbBalancedLevel($Trainer.party)>50
        newlevel=pbBalancedLevel($Trainer.party) + 10        
      end  
      if pbBalancedLevel($Trainer.party)>60
        newlevel=pbBalancedLevel($Trainer.party) + 12        
      end  
      if pbBalancedLevel($Trainer.party)>70
        newlevel=pbBalancedLevel($Trainer.party) + 14        
      end  
      if pbBalancedLevel($Trainer.party)>80
        newlevel=pbBalancedLevel($Trainer.party) + 16        
      end  
      if pbBalancedLevel($Trainer.party)>90
        newlevel=pbBalancedLevel($Trainer.party) + 10        
      end  
     newlevel=PBExperience::MAXLEVEL if newlevel>PBExperience::MAXLEVEL 
     pokemon.level=newlevel
    
     end
     if pokemon.species=212 #edit: the error is here, needs "==" instead of "="
     pokemon.pbLearnMove(:METALCLAW)
     pokemon.pbLearnMove(:ICEPUNCH)
     pokemon.pbLearnMove(:THUNDERPUNCH)
     end
   end
    
   
}

Luka S.J.

Jealous Croatian

Age 26
Male
Croatia
Seen 2 Hours Ago
Posted 11 Hours Ago
1,134 posts
10.6 Years
The if statement is not ignored, but there is priority when it comes to the order in which operations get executed. What happened was this:
1) pokemon.species gets set to 212
2) pokemon.species contains a numeric value that is not 0, that isn't a boolean type of false or a nil object
3) your if statement now checks whether or not pokemon.species will be true
4) since the variable has a numeric value of 212, this is treated as a logical true, so your if statement is actually triggered, not ignored

As for your other question, == is a bog standard logical operator that checks whether or not whatever is to the right of it is equal to what is to the left of it. You can find this operator in almost all programming languages. isConst? is a function specific to Pokemon Essentials, that checks whether a constant, denoted by a symbol (in your case :SCIZOR) can be found within your specified module (in your case PBSpecies). Then the value associated with this constant is retrieved and is compared against the value defined as the first parameter in the function (in your case pokemon.species) which the function then returns as a result. So as you can see, two very different things, which when applied in your context just happen to yield the same result.
Seen 1 Week Ago
Posted 1 Week Ago
51 posts
63 Days
Wow awesome Luka thx! I'll reread this ten times to be sure it's perfectly compiled in my brain.

I didn't know priority would happen inside a line, I thought everything was always red from top to down and left to right.
Are there functions or something else that have a priority in the entire script? or are the categories always red one by one from from top to down? in this second case I guess it would explain why all the tools we add have to be put in the end of the script, it's because they rewrite a lot of things? Which, I guess, is not as efficient as modifying the initial code but is way easier for sharing the tools with newbies. Am I wrong?

Luka S.J.

Jealous Croatian

Age 26
Male
Croatia
Seen 2 Hours Ago
Posted 11 Hours Ago
1,134 posts
10.6 Years
You're right in that the scripts get read sequentially, top to bottom, but lines get interpreted as a whole. Some operators take priority over others (for instance, putting things in parentheses will make it so that whatever calculation/operation is in those gets interpreted before the rest of the stuff on that line); you could liken this concept to your basic PEMDAS order of operations in Maths (2 + 2 * 2 = 6). In the case of an if statement, the whole boolean expression inside of it needs to be evaluated first, and then it's checked whether or not that expression equals true. The reason it is generally good to put new scripts below the others is that sometimes they reference existing functions, classes, modules.

Anyway, if you're serious about getting to know these things, I'd recommend brushing up on some basic concepts of programming and then Ruby in general. There are plenty of resources for you to use, here are a couple of them.
Advertiser Content