Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 945769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:48:19+00:00 2026-05-15T22:48:19+00:00

I have an integer that is initially 0 and, after calculations, often ends up

  • 0

I have an integer that is initially 0 and, after calculations, often ends up between 0 – 99. The problem is that since early on in the game, it calculates out to 0 or 1 often, it gets assigned as a TrueClass or FalseClass instead of a numerical value, which messes up a future x > 0 comparison. Is there a built-in Ruby way to force the variable into being a Fixnum/Integer type or will I have to monkeypatch it?

Here is the code it applies to:

Step 10: Compute the Target’s Magic Defense Multiplier

mdef_multi = self.mdef_multi

# Step 11: Modify the Magic Defense Multiplier
# If Toad
mdef_multi = 0 if user.states.include?(11)
# If Charging
mdef_multi = 0 if user.states.include?(30)
# If cast on self or PC onto PC
# 0 if PC targetting PC
mdef_multi = self.is_a?(Game_Actor) and user.is_a?(Game_Actor) ? 0 : mdef_multi
# 99 MDef Multi if max MDef
mdef_multi = self.is_a?(Game_Enemy) and mdef == 255 ? 99 : mdef_multi
# If Solo Multiplier is enabled
mdef_multi = obj.element_set.include?(26) ? 1 : mdef_multi

# Step 12: Modify the Spell Multiplier
hits = 0, missed = 0, evaded = 0
while spl_multi > 0
  spl_multi -= 1
  if rand(99) <= hit
    if mdef_multi > 0

The last line is where I run into the variable-type issue.
It’s technically RGSS2 from RPG Maker VX. And please excuse
my horrid commenting and coding style.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:48:20+00:00Added an answer on May 15, 2026 at 10:48 pm

    First of all, Ruby doesn’t auto-convert things, so your integer isn’t getting converted to a boolean because it’s 0 or 1.

    Instead, what’s happening is the line

    mdef_multi = self.is_a?(Game_Actor) and user.is_a?(Game_Actor) ? 0 : mdef_multi
    

    is being parsed as

    ( mdef_multi = self.is_a?(Game_Actor) ) and user.is_a?(Game_Actor) ? 0 : mdef_multi
    

    because of the way and works. Basically = has higher precendence than and, so the variable is only being set to the result before the and, which is a true/false value. && has a higher precedence than = though, so using && here should work. For this reason, some Ruby programmers recommend only using &&, never and. See http://blog.jayfields.com/2007/08/ruby-operator-precedence-of-and-which.html for more explanation.

    If you use && instead of and on this line and the next one, it should fix the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple regex, [\d]{1,5} that matches any integer between 0 and 99999.
Let's say I have an integer that I need to convert to a string
We have a file that has a 64 bit integer as a string in
I have a calc function in java script that takes three integer parameters, following
I have an integer output from a private controller action that I would like
I have a few integer keys that is needed to retrieve a value. What
I have a list of items heading that are all in INTEGER (yes the
Say if I have an initial string that could contain either an integer or
I have to use unsigned integers that could span to more than 4 bytes,
I have a function that expects real numbers (either integers or floats) as its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.