Roody's Lessons Somewhat Learned
Posted: Wed Jul 28, 2010 4:40 pm
I'm one of those guys who tries to write IF despite having almost no programming knowledge. Death To My Enemies would not exist without some help I received coding an array.
Anyhow, I've been keeping track of the problems I'm running into and their solutions since picking Hugo back up earlier this year. I'm going to share them here. Hopefully, some of it will help other people for whom programming is new.
Here's just a bunch of stuff to start off with:
scoring
I've noticed a couple things wrong with the routine PrintScore(end_of_game) in hugolib.h. First off, the line "print ranking[(score*100)/MAX_SCORE*MAX_RANK/100]" should end with a ";". As it is, there is a new line where there shouldn't be, resulting in something like:
! A complicated formula, since only
! integer division is allowed:
!
So I was led to believe that irrational numbers were screwing things up. In my game, I've replaced the line with "print ranking[(score*MAX_RANK)/MAX_SCORE];" MAX_RANK in this instance is the number of ranks, not including the ranking for 0 points. Anyhow, this may not be a perfect equation but it has worked in all of the examples I tested it with.
attributes vs. properties
In my Hugo game-coding so far, I found that I liked to check the state of my objects with the "special" attribute (examples: see if the player had searched something yet, whether something was broke or functional, etc.). The trouble with this is that I'd need another attribute if I had an object with more variables to check, and I was a bit confused about whether new attributes needed to be aliased to other attributes.
Eventually, I realized I could do a lot of what I was doing with properties instead. Properties don't only need to be used for drinks.left counts in soda can objects and the like. One of the results of this method, I've found, is that my new properties make the code easier to read since their names are usually a bit more specific than "special," and one property can be assigned as many states as I want instead of just the is/is not aspect of an attribute.
proper before/after usage
As mentioned in the manual, before and after have usage specifiers like object, xobject, actor, and location. In some instances, I found myself trying to catch verbs with the wrong usage specifier (using object or xobject when I should have been using location or actor). I think because object and xobject were the easiest for me to grasp, I gravitated towards those options unnecessarily.
Be sure to take a look at the order of before routine checks on page 127 of the manual to help determine where you need to catch a verb.
restart without prompt
In a joke game I wrote for a friend, I had a computer on which you could play the game you were already playing, so I wanted "play game" to act like "RESTART" without the "are you sure? y/n" prompt.
Now, this is kind of a horrible idea and shouldn't be emulated, but I thought I'd share the code in case a similar problem comes up for someone else for whom the answer isn't instantly obvious.
(In the game, the text adventure was on a phone, so >PLAY GAME would set phone as special and then Perform(&DoRestart) )
It's worth noting that this approach did not work:
edit: It occurs to me that all I need to do to force a restart was to add this code to the >PLAY GAME response:
capitalized nouns
I recently found that Hugo hates them (well, at least, it refused to let me refer to my character within the game). I'm sure it's mentioned somewhere, but it's just one of those things someone like myself might forget (and did).
clearing the screen
My work-in-progress uses Christopher Tate's converse.h extension, which uses the status line for dialogue choices during conversations. I found that restarting the game while in conversation left the choices on the top of the screen no matter how many times I put in lines changing status line height or cls's in my init code.
Johnny Rivera suggested I put "window 0" early in my init. This did the trick. I would suggest anyone who finds themselves in a similar situation do the same.
Anyhow, I've been keeping track of the problems I'm running into and their solutions since picking Hugo back up earlier this year. I'm going to share them here. Hopefully, some of it will help other people for whom programming is new.
Here's just a bunch of stuff to start off with:
scoring
I've noticed a couple things wrong with the routine PrintScore(end_of_game) in hugolib.h. First off, the line "print ranking[(score*100)/MAX_SCORE*MAX_RANK/100]" should end with a ";". As it is, there is a new line where there shouldn't be, resulting in something like:
Secondly, I've found that the default equation didn't work for my 30 point/ 4 ranked game. The comment describes it as thus:You have scored a total of 10 out of 10, giving you the rank of MASTERMIND
.
! A complicated formula, since only
! integer division is allowed:
!
So I was led to believe that irrational numbers were screwing things up. In my game, I've replaced the line with "print ranking[(score*MAX_RANK)/MAX_SCORE];" MAX_RANK in this instance is the number of ranks, not including the ranking for 0 points. Anyhow, this may not be a perfect equation but it has worked in all of the examples I tested it with.
attributes vs. properties
In my Hugo game-coding so far, I found that I liked to check the state of my objects with the "special" attribute (examples: see if the player had searched something yet, whether something was broke or functional, etc.). The trouble with this is that I'd need another attribute if I had an object with more variables to check, and I was a bit confused about whether new attributes needed to be aliased to other attributes.
Eventually, I realized I could do a lot of what I was doing with properties instead. Properties don't only need to be used for drinks.left counts in soda can objects and the like. One of the results of this method, I've found, is that my new properties make the code easier to read since their names are usually a bit more specific than "special," and one property can be assigned as many states as I want instead of just the is/is not aspect of an attribute.
proper before/after usage
As mentioned in the manual, before and after have usage specifiers like object, xobject, actor, and location. In some instances, I found myself trying to catch verbs with the wrong usage specifier (using object or xobject when I should have been using location or actor). I think because object and xobject were the easiest for me to grasp, I gravitated towards those options unnecessarily.
Be sure to take a look at the order of before routine checks on page 127 of the manual to help determine where you need to catch a verb.
restart without prompt
In a joke game I wrote for a friend, I had a computer on which you could play the game you were already playing, so I wanted "play game" to act like "RESTART" without the "are you sure? y/n" prompt.
Now, this is kind of a horrible idea and shouldn't be emulated, but I thought I'd share the code in case a similar problem comes up for someone else for whom the answer isn't instantly obvious.
(In the game, the text adventure was on a phone, so >PLAY GAME would set phone as special and then Perform(&DoRestart) )
Code: Select all
player_character you "you"
{
before
{
actor DoRestart
{
if phone is special
{ word[1] = "yes"
if YesOrNo = true
{
if not restart
VMessage(&DoRestart, 2) ! "Unable to restart."
}
}
else
return false
}
}
}
Code: Select all
before
{
actor {
if verbroutine = &DoRestart
Code: Select all
if not restart
"huh, it didn't restart"
capitalized nouns
I recently found that Hugo hates them (well, at least, it refused to let me refer to my character within the game). I'm sure it's mentioned somewhere, but it's just one of those things someone like myself might forget (and did).
clearing the screen
My work-in-progress uses Christopher Tate's converse.h extension, which uses the status line for dialogue choices during conversations. I found that restarting the game while in conversation left the choices on the top of the screen no matter how many times I put in lines changing status line height or cls's in my init code.
Johnny Rivera suggested I put "window 0" early in my init. This did the trick. I would suggest anyone who finds themselves in a similar situation do the same.