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.

Syntax Error

I keep getting an error with the following section of a script and I'm not entirely sure why.
I'm assuming its because I've done something wrong in the mix of the .chop's and switching between strings and integers but due to my lack of scripting skills and the fact it seemed to work in the fxri, I'm not quite sure whats wrong.
Code:
      
atk = attacker.atk.to_s
D  = atk.chop.chop.to_i    # ~these two
S = atk[-2,2].to_i            # ~
self.damage = D * S

Thanks for any help =)
 
ah sorry,
it says its a syntax error

as for the script its just an edit I'm trying to do to the battle formula
to make it so it breaks apart a weapons attack value in to two parts
ie: 1230 into 12 & 30
 
Well, don't capitalize the names of variables - they should start with a lowercase letter. An Upper Case Letter beginning the name denotes a constant and/or class names. So:

use d, not D
use s, not S

and I would suggest giving them more descriptive names anyway.

Also, .chop.chop?

I don't think that chop is a method that applies to strings. If you want to get the first two digits then atk[0, 2].to_i would work, or atk.slice (0, 2).to_i perhaps
 
I've never heard of the method, so I guess I've learned something too. I'm glad you have it working, but it does seem like a roundabout way to do it, converting it to a string and back to integers and all. I would suggest something like this:

atk = attacker.atk
d = atk / 100
s = atk % 100

It probably doesn't make a difference in this case though. Just seemed foreign to me :) Good luck with your script.
 

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