• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Eventing Question] all wild encounter are the same

153
Posts
4
Years
    • Seen Feb 4, 2020
    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


    Code:
    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
        
       
    }
     
    Last edited:
    153
    Posts
    4
    Years
    • Seen Feb 4, 2020
    Solved.

    I changed the line
    Code:
    if pokemon.species==212
    by
    Code:
    if isConst?(pokemon.species,PBSpecies,:SCIZOR)
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    Just for the record you have this line:
    Code:
         if pokemon.species=212
    Which, as you noticed turns every Pokémon into number 212.
    You meant to write what you posted in your update:
    Code:
         if pokemon.species==212
    Which compares the species number, instead of setting it :)
     
    153
    Posts
    4
    Years
    • Seen Feb 4, 2020
    oh yeah so the mistake was not what I thought I didn't realise I used only one "="
    so the "if" is ignored when you write if pokemon.species=212?
    then what is the difference between
    Code:
    if pokemon.species==212
    and
    Code:
    if isConst?(pokemon.species,PBSpecies,:SCIZOR)
    ?
    Thank you for your comment
     
    Last edited:

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    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.
     
    Last edited:
    153
    Posts
    4
    Years
    • Seen Feb 4, 2020
    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?
     
    Last edited:

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    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.
     
    Last edited:
    153
    Posts
    4
    Years
    • Seen Feb 4, 2020
    I'm dead serious about learning. Thx for the links I'll check these asap :)
     
    Back
    Top