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

  • SEARCH
  • Home
  • 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 6569065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:34:47+00:00 2026-05-25T14:34:47+00:00

I have a model, Statistic, that has 6 statistics for a Character model. Users

  • 0

I have a model, Statistic, that has 6 statistics for a Character model. Users can enter values for Strength, Intelligence and so on. What I want to do is automatically assign a value for a bonus or a penalty based on the value entered by the user. For example, if a 10 or 11 is entered, the bonus will be 0. If a 14 or 15 is entered, it will be 2. Any tips on how to write this method? Thanks!


This has been a big help, but I’ve hit another snag. I’ve defined this in the Show method in Characters controller as such:

@con_modifier = @character.statistic.con_modifier

So I can call it from my Character view (where most of this information is displayed) I’ve got a Fortitude model for Fortitude saves, and I’d like to use the con_modifier in the logic to calculate a total. How do I call a foreign model correctly this way? I have:

def total
  fortitude_base.to_i + ability.to_i + magic.to_i + misc.to_i
end

And I tried changing it to:

def total
  fortitude_base.to_i + @con_modifier + magic.to_i + misc.to_i
end

But then I get this error:

nil can't be coerced into Fixnum

So obviously it isn’t calling up the correct information. Any ideas? Do I need to define it in my Fortitudes controller as well, or can I simply define it in the Fortitude model and call it in the view that way?

  • 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-25T14:34:48+00:00Added an answer on May 25, 2026 at 2:34 pm

    Smells like D&D. Consulting my old Player’s Handbook indicates that the modifier for an attribute value of n is simply (n - 10) / 2.

    So you’d just the attribute value through that simple formula and you’d have your modifier. I’d probably have a class method in the Attribute class:

    class Attribute
        #...
        def self.modifier_for(attribute_score)
            (attribute_score.to_i - 10) / 2
        end
    end
    

    And then hook that up to your Player with something like this:

    class Player
        #...
        def wis_modifier
            Attribute.modifier_for(wis)
        end
        def modifier(attr)
            self.send(attr.to_s + '_modifier')
        end
    end
    
    will_save += p.modifier(:wis)
    

    You could probably get fancier if you wanted but simple is a good start and you can always get your local cleric to heal your code (or use your +3 Flaming Ax of Code Refactoring) later if necessary.

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

Sidebar

Related Questions

I have a Model called statistics which has a value field that contains Goals
I have model Article it has field title with some text that may contain
In my controller I have model operations that can return empty results. I've setup
I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to
I have a model, ContactEmail that has a date_sent attribute and an email_id, referencing
Lets say I have some Django model that has a list of numbers as
I have model Foo which has field bar. The bar field should be unique,
If I have Model.objects.all() I want to get only one object for any content_object=foo,
I have implicitly made this a community wiki seeing that the answers can be
Suppose we have two variables that we wish to build a model from: set.seed(10239)

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.