intfiction.org

The Interactive Fiction Community Forum
It is currently Tue May 21, 2013 12:37 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: "Distress" Source Code
PostPosted: Wed Aug 09, 2006 1:10 pm 
Offline
Site Admin
User avatar

Joined: Sat Dec 22, 2007 9:54 am
Posts: 951
Location: Wichita, KS
This has been announced already, but the source code for "Distress" is available at my website:

http://www.sidneymerk.com/zips/dist_src.zip

I'd like to also release some library extensions, when I get a chance. :)


Top
 Profile Send private message  
 
PostPosted: Wed Aug 09, 2006 1:49 pm 
Offline
User avatar

Joined: Sat Dec 22, 2007 9:03 pm
Posts: 175
I noticed on the sources for both Distress and Trading Punches that you normally set a routine up just for printing really large blocks of text - then access it later by running the routine with the appropriate, ah, argument values (I don't know if that's the right term).

Is it better to code in Hugo that way and save memory, by using the "print" statement more than just leaving the blocks of text in quotation marks? I read somewhere in the manual that text blocks without the "print" statement are the ones saved in the game's file.

Thanks!

EDIT: I've taken the italics off the game titles.


Top
 Profile  
 
PostPosted: Wed Aug 09, 2006 4:18 pm 
Offline
Site Admin
User avatar

Joined: Sat Dec 22, 2007 9:54 am
Posts: 951
Location: Wichita, KS
I'd have to check the manual to know for sure. I *think* that anything printed with the "print" statement is functionally the same as just doing text. In other words:

print "This is a test."

and

"This is a test."

will both store "This is a test." as a dictionary entry. In fact, if you used that exact quoted string 50 times elsewhere in the program, it's still only going to take up one spot in the dictionary. Everywhere you print it, it'll just "print" the value of that dictionary entry.

The thing is, if "This is a test." is part of a larger print statement (in other words, what's in quotes isn't *exactly* that), then it's going to count as another dictionary entry. If you look hard enough in the Hugo library, you can even see where Kent will break apart long strings just so that the "bits" of it hit on phrases already used.

In other words, if you have already used "This is" and "a test." in other places (alone, so as to be self-contained as dictionary entries), then the following bit would be more efficient space-wise:

print "This is"; " "; "a test."

Remember that *everything* enclosed in quotes ends up as a dictionary entry. At compile-time, I *think* multi-line text such as this...

"This is
a test of
something."

...ends up as a single dictionary entry, formatted with a space between the lines. Kent could probably say for sure.

As for why I use a PrintMessage() routine in my games, it's not really to save memory. Well, I do re-use some messages, but if I just cut and pasted the exact same thing in multiple spots, it's still just going to use one dictionary entry (as long as they're identical). I do it more so that I only need to change the text in one place and all routines that "print" the message will then use the updated version. It's also so I can skim through the text all at once, in one place (eventually I export it out to spell-check, but this helps until then). In my current WIP, I'm putting practially *all* text in PrintMessage() blocks, even if it's simple.

Argument values, parameters, same thing. I'm starting to get a little better at this, in my current WIP. I'm using objects as parameters (well, the object "number" is the parameter), so that I can have one single "long_desc" handler that just checks to see what object we're describing. That type of thing. Well, I don't do that in all cases, but since I've started putting little headers on each one, it's easier for me to figure out later what each of the messages was intended for. Smile

I'm also figuring out things I did in Distress, and *especially* in Trading Punches, that could have been done much easier. Like, making custom properties/attributes where needed, calling more routines that are already in the library instead of re-inventing them, etc. Smile


Top
 Profile Send private message  
 
PostPosted: Wed Aug 09, 2006 4:40 pm 
Offline
User avatar

Joined: Sat Dec 22, 2007 9:03 pm
Posts: 175
Merk wrote:
I'd have to check the manual to know for sure. I *think* that anything printed with the "print" statement is functionally the same as just doing text. In other words:

print "This is a test."

and

"This is a test."

will both store "This is a test." as a dictionary entry. In fact, if you used that exact quoted string 50 times elsewhere in the program, it's still only going to take up one spot in the dictionary. Everywhere you print it, it'll just "print" the value of that dictionary entry.
(snipped rest of quote)

Thanks for explaining that. I'll probably have to re-read that section of the Hugo manual.

Merk wrote:
As for why I use a PrintMessage() routine in my games, it's not really to save memory. Well, I do re-use some messages, but if I just cut and pasted the exact same thing in multiple spots, it's still just going to use one dictionary entry (as long as they're identical). I do it more so that I only need to change the text in one place and all routines that "print" the message will then use the updated version. It's also so I can skim through the text all at once, in one place (eventually I export it out to spell-check, but this helps until then).

I was thinking you were trying to put it all in one place for easier reference *and* save memory. But that wasn't the actual purpose as you've explained...

Thanks again. Let's just hope the things inside square brackets work this time. :)


Top
 Profile  
 
PostPosted: Wed Aug 09, 2006 4:47 pm 
Offline
Site Admin
User avatar

Joined: Sat Dec 22, 2007 9:54 am
Posts: 951
Location: Wichita, KS
Yeah, unless I'm way off the mark, the Hugo compiler builds a dictionary of all the quote-enclosed strings in the game. Each time it parses the source code to another quoted string, it compares it to all the existing dictionary entries. In essence, everything printed becomes just a call to print a certain dictionary entry. If you print the same thing in multiple places, the .HEX file ends up with a "print" to the same dictionary entry on all of them. I'm *pretty* sure that's how it works.

It'd probably be easy to test. Write a simple program where you print "This is a test 1111" a hundred times in a row (using 100 different print statements). See how big the compiled .HEX file is. Then, change it so that the number on each line is different. The .HEX file ought to get a lot bigger.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group