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 8637619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:31:21+00:00 2026-06-12T10:31:21+00:00

A few days ago I made a lord generator for a game called Broken

  • 0

A few days ago I made a lord generator for a game called Broken History I play with my mates, I started the code myself but ended up getting help with the code to finish it.

I then set about making a char gen for the same game, using the exact same methods that worked before, everything was looking good every element did what it was supposed to. However, when I got the resulting text the first time the variable curFaction was called it read undefined the second time it read the faction the user chose in the select box i.e. Saxathia. The variable is assigned in the $(document).ready() function so in theory is should be assigned before it is called right?

I can’t think why this happens, the variable is called as part of an array does that make any difference?

enter image description here

Here is the jsLint http://jsfiddle.net/CYe8J/31/

  • 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-06-12T10:31:23+00:00Added an answer on June 12, 2026 at 10:31 am

    Your problem is that you are setting the character description string when the page is loaded, before the user has selected a faction.

    // curFaction is undefined here, as user cannot select a faction 
    // *before* the page is loaded!!
    var aLevel[1] = "Description1 of guy from " + curFaction + ".";
    

    The quickest fix is to generate the description as and when it is required. One way to do this would be to store a function in aLevel, rather than a string, like the following:

    var aLevel[1] = function () { "Description1 of guy from " + curFaction + "."; };
    var aLevel[2] = function () { "Description2 of guy from " + curFaction + "."; };
    var aLevel[3] = function () { "Description3 of guy from " + curFaction + "."; };
    

    Then, when you need your description, call the function:

    // Original code:
    "Stuff about claim on throne. " + aLevel[temp6] + ".";
    
    // New code - note brackets after "aLevel[temp6]"
    "Stuff about claim on throne. " + aLevel[temp6]() + ".";
    

    I’ve created a Fiddle showing this.

    As an aside, your code could generally be refactored quite a lot – as a rule, if you find you are writing the same algorithm over and over again, then you need to remember the DRY principle 🙂

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

Sidebar

Related Questions

I started with PHP a few days ago. I made some querys to my
I made a similar question a few days ago, but now I have new
Few days ago all was ok: when I started my web-site with Silverlight 4.0
I made a backup of my MySQL DB's a few days ago, its a
Few days ago I started experimenting with Mercurial, and everything went great, until I
A few days ago I started with Ubuntu for the first time. I want
A few days ago I posted some code like this: StreamWriter writer = new
Since a few days ago I've started to feel interested in Unit Testing and
I just started using Kohana a couple days ago, and I have a few
A few days ago it was just fine. I haven't made any change to

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.