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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:49:13+00:00 2026-06-13T08:49:13+00:00

This will seem like an odd problem to have. I’ve got this bit of

  • 0

This will seem like an odd problem to have. I’ve got this bit of Ruby code that takes an input string, uses scan and flatten to extract a particular value, and the hope is to then operate off that value in an if...then statement, but I’m having issues.

My input string describes the number of ‘dangerous creatures’ in the area. The string, when describing no dangerous creatures or two or more creatures is always standard, something like:

“no dangerous creatures in the area” or “one dangerous creature…” and so on.

I’m using this to fetch the word representing the number of creatures as: “no”, “one”, “two”, and so on in hopes of converting these to numeric values later on – “no” = 0, “one” = 1, etc.

To do this, I use:

crittercount = strcheck.scan(/a*(no|one|two|three|four|five|six|seven|eight|nine|ten)a*/)

Then I go and do an if then on the variable crittercount saying:

if crittercount == "no"
  critters = 0
  ... exit and go do something with the var...
end

I do this for each one. (when I get this issue figured out I’ll use if..elsif..end)

if crittercount == "one"
  critters = 1
  ... exit and go do something with the var...
end
...

After crittercount == "ten" I just use

if crittercount == "ten"
  critters = 10
else
  critters = 99
end

Here is the problem: I have a variable called maxcreatures equal to 10. I take the strcheck value of “no dangerous creatures in the area” for example, I print out the value it returns that exact string. Then I print out the crittercount variable, in this example, I get “no”.

When I get through my if..then.. statements though, I evaluate what to do using:

if critters > maxcreatures
  print "Maximum Creatures " + critters.to_s + " and maximum is #{maxcreatures}.  Lets Bail"
else
  print "Critter count " + critters.to_s  + " is less than #{maxcritters} Keep going."
end

In every situation I’m getting 99 and I swear I’ve tried everything. I tried using .flatten at the end of the regex, I tried using .strip on the crittercount var. I’m hoping someone looks at this and goes ‘duh, try this.’

On request here is all the code, there are calls in here to other functions that may not make sense…

maxcritters = 2

critters = 0


put "count critter"
strcheck = matchfind "You notice ?"

crittercount = strcheck.scan(/a*(no|one|two|three|four|five|six|seven|eight|nine|ten)a*/)
echo strcheck
echo crittercount
crittercount = crittercount.strip
if crittercount == "no"
    critters = 0
    goto "roundup"
end
if crittercount  == "one"
    critters = 1
    goto "roundup"
end
if crittercount == "two"
    critters = 2
    goto "roundup"
end
if crittercount == "three"
    critters = 3
    goto "roundup"
end
if crittercount == "four"
    critters = 4
    goto "roundup"
end
if crittercount == "five"
    critters = 5
    goto "roundup"
end
if crittercount == "six"
    critters = 6
    goto "roundup"
end
if crittercount == "seven"
    critters = 7
else
critters = 99
end

roundup:
if critters > maxcritters
echo "Maximum Creatures " + critters.to_s + " and maximum is #{maxcritters}.  Lets Bail"
critters == nil
fput "retreat"

else
    echo "Critter count " + critters.to_s  + " is below maximum of #{maxcritters} - We're cool.  Keep going."
    critters == nil
    goto "combatcheck"
end
  • 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-13T08:49:14+00:00Added an answer on June 13, 2026 at 8:49 am

    The problem is that crittercount is an array, not a string. Therefore if crittercount == "no" etc. will never be true and you will always end up in your last else.

    Solution is to change your code to:

    crittercount = strcheck.scan(/no|one|two|three|four|five|six|seven|eight|nine|ten/).first
    

    With this crittercount will be either a string or nil and the rest of your code will work as expected.

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

Sidebar

Related Questions

this may seem odd, but I actually need a PHP script that WILL time-out,
This will probably seem like a noob question but I have managed to intall
I seem to have some weird issue going on that I am sure will
This will probably seem like a really simple question, and I am quite confused
This may seem like an odd question, but I need to find a closed-source
So I have a function that looks like this: @SuppressWarnings(unchecked) public static <E> Set<E>
This may seem like an odd one, but I want to be able to
Hi I have this following code with jquery , so it will alternate colors
reviewing the code example on this page, it seem like the example is initializing
As odd as it may seem I have a part of my script that

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.