Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Why is my array acting like this?

Dko

Member

Hiya could someone help me with this? I have a array that is looped thru using array.shift to see which item first thru last is in each space. Then I have a if state ment that checks weather what was returned wasn't nil or "" But some how when I get to thru every item in the array the if statement still lets me thru. But if I print the value of the array there is nothing there nor does it come up nil. Here is what my code looks like to give an idea.

Code:
str_temp = @attacks_str.shift
        if @attacks_str != nil or @attacks_str != ""
          #medium Strength hit
          if str_temp == 1    
            actor_attack_effect($ATTACK, 2)
          end
          #Strong Stength hit
          if str_temp == 2  
            actor_attack_effect($ATTACK_HIGH, 4)
          end
          #Weak Stength hit
          if str_temp == 3
            actor_attack_effect($ATTACK_WEAK, 6)
          end
        end

EDIT: I guess a better explination of what I need help with is that I don't want to have the if statement at the top be true once ive shifted every element in the array.
 

Zeriab

Sponsor

'str_temp = @attacks_str.shift' actually removes the element it returns
If you don't push them back into the array with '@attacks_str.push(str_temp)' or something similar you will eventually remove all elements from the array.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top