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.

I hate syntax errors...

Hi guys, I'm cocicookie, and I'm the NEW account for Zeldabud (I'm now bored TOTALLY of that name). Now thats out of the way, onto my problem: A stupid, good for nothing, sysntax error :/

I've been modifying the battle alogimths to be set up so it plays like Dungeons and Dragons. But for some reason, now I've put in all the Normal Hit and Critical Hit code, I get a syntax error for no apparent reason...

Here is the modified alogrimth code:
Code:
  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #     attacker : battler
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
    # Reset critical hit
    critical_chance = false
    critical_result = false
    # Hit detection
    hit_roll = rand(19) + 1
    if hit_roll = 1
      hit_result == false
    else if hit_roll = 20
      hit_result == true
      critical_chance == true
    else
      hit_result = (hit_roll + attacker.dex >= self.agi)
    end
    # Check for critical
    if critical_chance = true
      critical_roll = rand(19) + 1
      if critical_roll = 1
        critical_result == false
      else if hit_roll = 20
        critical_result == true
      else
        critical_result = (hit_roll + attacker.dex >= self.agi)
      end
    end
    # If hit occurs
    if hit_result == true
      # Calculate basic damage
      atk = rand(attacker.dice)
      if atk <= 1
        atk = 1
      end
      self.damage = (atk + attacker.atk) - self.pdef
    end
    # If critical hit occurs
    if critical_result == true
      self.damage * 2
    end
    # If hit occurs
    if hit_result == true
      # State Removed by Shock
      remove_states_shock
      # Substract damage from HP
      self.hp -= self.damage
      # State change
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    # When missing
    else
      # Set damage to "Miss"
      self.damage = "Miss"
      # Clear critical flag
      critical_chance = false
      critical_result = false
    end
    # End Method
    return true
  end

Anyone see the problem with it?
 
else if hit_roll = 20

it should be elsif, not else if.
The else if is creating the syntax error because the program is expecting ends that aren't there.
There were a couple of those, and that's all the jumped out at me on quick inspection.
 
Thanks for your help, I'm gonna fix the script now and hope it works.

EDIT: It worked! Had to modify my script a little more, because it wasn't setting hit_result to anything, but now it's working, I can mess around with the status screen more, and work on skills.
 

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