Making things the hard way
#11
After a long hiatus and having reread the whole thread, I got to say that I still defend the usefulness of my initial position BUT I don't mind if we include a specific kind of safeguard in our methods; even if we had already crafted some test scripts in the process. Yet, I cannot claim that raising errors is the only way to prevent serious errors from showing up later on.

Let us say we passed a name like "Rufus" to the int_month method above.

Code:
int_month("Rufus")

It would display the following message on screen.

Quote:Current Month is Rufus or better known as invalid.

But that only happens because we chose to include the month variable there. That might not always be the case in any ingame script. Thus we need to come up with something else to fix this issue.

Code:
def int_month(month)
  # We are adding some New Code Here
  if !month.is_a?(Integer)
    puts "TypeError: #{month} is not an integer but some #{month.class} class object!"
  elsif !month.between?(1, 12)
    puts "RangeError: Wrong Value! found #{month}, expected 1 through 12"
  end
  # Most of the Old Code Goes Here
  month_name = months[month]
end

So passing "Rufus" as an argument would print the following message on screen:


Quote:TypeError: Rufus is not an integer but some String class object!


Or if had passed 20 instead...


Quote:RangeError: Wrong Value! found 20, expected 1 through 12


You could replace puts with raise if you prefer.

But why do I care about this if and elsif statements over there? Confused
Didn't I say it's better to let the game spit an error message on your face? Thinking

Well, it's true I stated that letting users cause certain runtime errors might be helpful, yet, we can and should avoid them if we are handling simple stuff like strings or numbers in weak typed languages like Ruby and its derivative RGSS. This does not mean we should let people try to load a non existing file that is supposed to be displayed as, I dunno, some backdrop on a given scene.

You see, sometimes the array or hash approach might be helpful but not always and this is something extremely important to keep in mind. You got to know the existing limitations of a language or an implementation of any method and plan accordingly. This also means that you got to accept that the time might have come to rewrite a whole method or script from scratch if deemed necessary by your current circumstances.
"For God has not destined us for wrath, but for obtaining salvation through our Lord Jesus Christ," 1 Thessalonians 5:9

Maranatha!

The Internet might be either your friend or enemy. It just depends on whether or not she has a bad hair day.

[Image: SP1-Scripter.png]
[Image: SP1-Writer.png]
[Image: SP1-Poet.png]
[Image: SP1-PixelArtist.png]
[Image: SP1-Reporter.png]

My Original Stories (available in English and Spanish)

List of Compiled Binary Executables I have published...
HiddenChest & Roole

Give me a free copy of your completed game if you include at least 3 of my scripts! Laughing + Tongue sticking out

Just some scripts I've already published on the board...
KyoGemBoost XP VX & ACE, RandomEnkounters XP, KSkillShop XP, Kolloseum States XP, KEvents XP, KScenario XP & Gosu, KyoPrizeShop XP Mangostan, Kuests XP, KyoDiscounts XP VX, ACE & MV, KChest XP VX & ACE 2016, KTelePort XP, KSkillMax XP & VX & ACE, Gem Roulette XP VX & VX Ace, KRespawnPoint XP, VX & VX Ace, GiveAway XP VX & ACE, Klearance XP VX & ACE, KUnits XP VX, ACE & Gosu 2017, KLevel XP, KRumors XP & ACE, KMonsterPals XP VX & ACE, KStatsRefill XP VX & ACE, KLotto XP VX & ACE, KItemDesc XP & VX, KPocket XP & VX, OpenChest XP VX & ACE
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Making a "Wait Until Button Input" PK8 1 6,345 05-28-2012, 12:50 PM
Last Post: yamina-chan
   Making a Successful comedy RPG DerVVulfman 0 5,299 05-17-2011, 05:18 AM
Last Post: DerVVulfman
   The Ultimate Guide for Making Nifty Fantasy RPGs by Magus Masque DerVVulfman 5 11,459 06-07-2010, 02:44 PM
Last Post: sakhawat21
   Making an Impact, Part 3 Kaos Tenshi 0 3,881 01-19-2009, 05:33 PM
Last Post: Kaos Tenshi
   Making an Impact, Part 2 Kaos Tenshi 0 3,826 01-19-2009, 05:30 PM
Last Post: Kaos Tenshi
   Making An Impact, Part 1 Kaos Tenshi 0 3,906 01-19-2009, 05:26 PM
Last Post: Kaos Tenshi
   Rose Skye's Game Making Tips RoseSkye 0 3,714 12-06-2008, 05:06 PM
Last Post: RoseSkye



Users browsing this thread: 1 Guest(s)