"You" to [Character Name] Question

Shoal
09 Aug 2003, 06:02
Hi,

I never liked the idea of "You" being the character in a game, so I'm working on a game in which "You" is replaced by the name of the character. Let's call him "Bob" for now (not his actual name).

I've managed to replace "You" with "Bob" for everything I know of except the inventory list. When you type "inventory", it says "You are carrying:"

How do you make it say, "Bob is carrying:"?

Any help would be greatly appreciated.

Thanks,

Shoal

Alex
09 Aug 2003, 08:18
You could do this by overriding the "inventory", "inv" and "i" commands. Here's some ASL code I've knocked up - this is untested though:


command <inventory; inv; i> {
set numeric <CurrentObject; 1>
for each object in <inventory> {

' Go through the inventory and add object names in bold
' to an ObjectName array

set string <ObjectName[CurrentObject]; |b#@quest.thing#|xb>

' Add prefix and suffix if they exist

if ( #(quest.thing):prefix# <> ) then set <ObjectName[CurrentObject]; #(quest.thing):prefix# #ObjectName[CurrentObject]#>
if ( #(quest.thing):suffix# <> ) then set <ObjectName[CurrentObject]; #ObjectName[CurrentObject]# #(quest.thing):suffix#>

' Increment the CurrentObject counter

set numeric <CurrentObject; %CurrentObject% + 1>
}

if ( %CurrentObject% = 1 ) then {
' The player isn't carrying anything
msg <Bob is not carrying anything.>
}
else {
' decrement CurrentObject as we will have added an extra 1
' to it after adding the last object
set <CurrentObject; %CurrentObject% - 1>

msg <Bob is carrying:|n>

for <i; 1; %CurrentObject%> {
msg <#ObjectName[i]#>

' Add a comma after all but the last object printed
if ( %i% <> %CurrentObject% ) then msg <, >
}
}
}

Alex
09 Aug 2003, 08:21
Correction: in the final "for" loop, the line

msg <#ObjectName[i]#>

should read

msg <#ObjectName[i]#|xn>

to stop a new line being printed after the object name.


Similarly

if ( %i% <> %CurrentObject% ) then msg <, >

should read

if ( %i% <> %CurrentObject% ) then msg <, |xn> else msg <|n>

to stop a new line being printed after the comma, and to finish the line when the printing of the object names has finished.

I did say it was untested! :)

Shoal
09 Aug 2003, 18:31
What you gave me works, it just needs a little modification.

Here is what it displays:

Bob is carrying:
an object one !, an object two !, an object 3 !



The "an"s were added by me as object prefixes. I also removed the new line after "Bob is carrying".

First of all, how do I get rid of the exclamation points and the space that preceeds them?

I also changed "Bob is not carrying:" to "Bob is carrying:", because, if I didn't, it would display "Bob is not carrying:" and then list all his inventory items.

Also, how do I make the first object prefix capitalized, ala "An", and add an "and" and period before and after the last object, respectively?

I'm sorry I'm asking this complicated question, but I really, really suck at programming! Why else do you think I'm using an editor to make something as simple as a text adventure? :)

You're being a huge help! Thanks!

Shoal

Shoal
09 Aug 2003, 20:26
Be sure to see my reply above as well.

I just discovered that since I didn't have any rooms to travel to, I didn't realize that it displays "You can go [direction or place]". :?

Dammit! It would be great if a feature could be added where you could edit those lines in a much easier fashion...

I need it to say "Bob can travel [direction or place]".

I know this all seems really stupid for something so small, but I want the players of my adventure to fall in love with the main character, not themselves. :(

I promise the name of anyone who helps out will be in the credits, if that helps! :) Thanks!

Shoal

I think Im Dead
09 Aug 2003, 22:00
That's as simple as editing the room description format. The Quest help documentation goes into how to change this in the category "How to... Customize Room Descriptions."

Basically it involves modifying these pieces of code...


description {
set string <indescription; $gettag(#quest.currentroom#;indescription)$>
if is <#indescription#;> then set string <indescription; You are in>
else {
set numeric <len; $lengthof(#indescription#)$>
set numeric <len; %len%-1>
set string <indescription; $left(#indescription#;%len%)$>
}
msg <#indescription# |b|cl#quest.formatroom#|xb|cb.>
if not is <#quest.doorways.out#;> then msg <You can go out to #quest.doorways.out#.>
if not is <#quest.doorways.dirs#;> then msg <You can go #quest.doorways.dirs#.>
if not is <#quest.doorways.places#;> then msg <You can go to #quest.doorways.places#.>
if not is <#quest.objects#;> then msg <You can see #quest.formatobjects#.>
msg <#quest.lookdesc#>
}


And putting it in your game definitions block.

Alex
09 Aug 2003, 22:01
Ah yes, forgot that if you don't have a prefix or suffix set then Quest will return an error and indicate it with an "!". You could replace:


if ( #(quest.thing):prefix# <> ) then set <ObjectName[CurrentObject]; #(quest.thing):prefix# #ObjectName[CurrentObject]#>
if ( #(quest.thing):suffix# <> ) then set <ObjectName[CurrentObject]; #ObjectName[CurrentObject]# #(quest.thing):suffix#>


with


if ( #(quest.thing):prefix# <> ! ) then set <ObjectName[CurrentObject]; #(quest.thing):prefix# #ObjectName[CurrentObject]#>
if ( #(quest.thing):suffix# <> ! ) then set <ObjectName[CurrentObject]; #ObjectName[CurrentObject]# #(quest.thing):suffix#>


This will leave a few ASL errors in your log though, but if you're not worried about that then it doesn't really matter.

To capitalise the "An", use the $capfirst$ function on the first item when printing the list. Replace the final loop with this:


for <i; 1; %CurrentObject%> {
if ( %i% = 1 ) then msg <$capfirst(#ObjectName[i]#)$> else msg <#ObjectName[i]#>

' Add a comma after all but the last object printed
if ( %i% <> %CurrentObject% ) then msg <, >
}



As for "Bob can go (direction or place)" you need to provide your own description-generating routine. You can do this using with "description" script in the "define game" block. For example:


description {
set string <indescription; $gettag(#quest.currentroom#;indescription)$>
if is <#indescription#;> then set string <indescription; You are in>
else {
set numeric <len; $lengthof(#indescription#)$>
set numeric <len; %len%-1>
set string <indescription; $left(#indescription#;%len%)$>
}
msg <#indescription# |b|cl#quest.formatroom#|xb|cb.>
if ( #quest.doorways.out# <> ) then msg <Bob can go out to #quest.doorways.out#.>
if ( #quest.doorways.dirs# <> ) then msg <Bob can go #quest.doorways.dirs#.>
if ( #quest.doorways.places# <> ) then msg <Bob can go to #quest.doorways.places#.>
if ( #quest.objects# <> ) then msg <Bob can see #quest.formatobjects#.>
msg <#quest.lookdesc#>
}

Alex
09 Aug 2003, 22:04
Woops again, I missed out the previous "|xn" corrections from that new correction. I'm sure you can work it out though. Looks like this posting untested code thing is a bit of a false economy :)

Alex
09 Aug 2003, 22:05
ITID beat me with the description thing by one minute, but we're saying the same thing.

Shoal
09 Aug 2003, 23:00
Okay, description stuff worked! Big thanks! :)

However, the inventory code still has some problems. With what you provided me, the exclamation points are gone, but now a new line is created for every new object in Bob's inventory. Also, there is no "and" before the last inventory item.

Also, you mentioned errors in the ASL code. What did you mean?

Thanks,

Shoal

I think Im Dead
10 Aug 2003, 02:40
It's probably not the easiest way of doing it but I'd suggest adding a section to the top of the inventory code, right after the for each object in <inventory>(or before to get a count first) that adds one to a numeric variable for each object in the inventory, then you can just test each variable's number and place an AND before the last one similar to the comma's after all the others.

Eh, the thoughts came out in my head right, but I'm fairly sure Gin effects something between the brain and mouth.

Shoal
10 Aug 2003, 04:57
I, uh, didn't understand any of that. I suck at programming, remember? Code scares me! I failed my basic programming class in my freshman year of college. :(

I need concrete, fully written-out code example... :(

Thanks,

Shoal

I think Im Dead
10 Aug 2003, 07:19
Ok it ain't pretty but here it is...

paste this part alongside your other commands in the .asl file



command <inventory; inv; i> {
set numeric <inv-count; 0>
set numeric <inv-total; 0>
for each object in <inventory> set numeric <inv-total; %inv-total% + 1>
if ( %inv-total% = 0 ) then set string <inv-list; nothing.|n> else {
for each object in <inventory> {
set numeric <inv-count; %inv-count% + 1>
if property <#quest.thing#; prefix> then set string <inv-item; $objectproperty(#quest.thing#; prefix)$ $displayname(#quest.thing#)$> else set string <inv-item; $displayname(#quest.thing#)$>
if property <#quest.thing#; suffix> then set string <inv-item; #inv-item# $objectproperty(#quest.thing#; suffix)$>
property <temp; %inv-count%=#inv-item#>
set string <inv-item; >
}
for <inv-create; 1; %inv-total%> if ( %inv-create% <> 1 ) and ( %inv-create% <> %inv-total% ) then set string <inv-list; #inv-list#, $objectproperty(temp; %inv-create%)$> else {
if ( %inv-create% = 1 ) and ( %inv-create% <> %inv-total% ) then set string <inv-list; $objectproperty(temp; %inv-create%)$>
if ( %inv-create% = %inv-total% ) and ( %inv-create% <> 1 ) then set string <inv-list; #inv-list# and $objectproperty(temp; %inv-create%)$.|n>
if ( %inv-create% = 1 ) and ( %inv-create% = %inv-total% ) then set string <inv-list; $objectproperty(temp; %inv-create%)$.|n>
}
}
msg <Bob is carrying #inv-list#>
}


paste this alongside where your rooms are defined, it's a temporary room, just there to make things easy to keep track of.


define room <temp>
end define


It works fine for me, tested it a few times with no problems. Adds the comma's and the elusive 'and' in the right place. Have fun.

Shoal
11 Aug 2003, 11:49
I'll test the code out as soon as I can get the ASL file to run... the new DAT that Alex gave me hates me. It crashes my ASL everytime.

Thanks,

Shoal

Alex
11 Aug 2003, 11:56
Hmm, I sent you a QDK.DAT for QDK 3.5 Beta, but I see you're actually using QDK 3.12, so this will be the reason you're having problems I think. I'll send you a corrected QDK.DAT for QDK 3.12 later on today.