gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Messages and Magic Cookies

#153791 - sgeos - Sun Apr 06, 2008 9:47 am

This is more of an encoding problem than a coding problem, but the two are related.

In any case, assume I have a message such as:
Code:
Who is your leader?<nl><choice:<party:0> <party:1> <party:2>><ff>
Do you come in peach?<nl><choice::yes :no :silence><ff>
Please wait a minute.

Clearly dealing with newlines and formfeeds is simple.
ASCII has special characters for this.
The problem is that other magic cookies need to inserted in the code.

<party> is a fairly simple inline function that takes one parameter.
It finds the party member at the Nth position and returns their name.
In order to get this to work, some sort of magic cookie needs to inlined in the message.
If I could assume ASCII, I would probably use 0xFF or something to that effect, but I'm going to assume unicode at this point.
Does anyone know of any magic cookie values that are unicode compatible?
Multibyte values are fine.

The data will be inlined as such:
Cookie Bytes, Function Indicator Bytes, Function Parameter Bytes

Note that <choice> requires a bunch of cookies- one to start it, one for each choice, and one to end it. This does not change the problem.

-Brendan

EDIT: Using end-user defined characters, although the obvious solutions, seems like the easy way out. I'm hoping that someone else has run into this or a similar problem and knows of an existing character code or value that makes sense as a cookie indicator.

#153903 - tepples - Tue Apr 08, 2008 1:55 am

There's always '<' (U+003C) to start a cookie and '>' (U+003E) to end it. If it works for HTML, and it works for various applications of XML, and it works for your ad-hoc metalanguage above, it can be made to work in a game.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#153905 - Dwedit - Tue Apr 08, 2008 2:32 am

In old games, people used various non-printable characters to accomplish control codes. Saves space compared with long ascii words.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#153947 - sgeos - Tue Apr 08, 2008 5:34 pm

tepples wrote:
There's always '<' (U+003C) to start a cookie and '>' (U+003E) to end it. If it works for HTML, and it works for various applications of XML, and it works for your ad-hoc metalanguage above, it can be made to work in a game.

That is actually ingenious. To the extent that '<' and '>' are reserved for tags, they will never be displayed in messages, so there will be no character mapping conflicts. Using the same characters in both representations may or maynot complicate the conversion regexp.

Dwedit wrote:
In old games, people used various non-printable characters to accomplish control codes.

That was the original plan. I was looking using "invalid" unicode values, as they do not run the risk of ...
In UTF-8, 0xFE and 0xFF are invalid value.
In UTF-16, high-high or low-low surrogate pairs are invalid.
I suppose things like the bell and vertical tab could always be used.

Dwedit wrote:
Saves space compared with long ascii words.

Writers need to be able to write in a language that A) they can type, and B) makes sense to humans. During the build, a regexp will replace the "long ascii words" with something a little more compact. My question is, what, specifically, should the magic cookie marker be?

For what it is worth, the cookie structure is:
[Cookie Marker Byte(s)] [Function Code] [Parameter Count] [Parameter Bytes]
Some parameters are constants, while others are passed into the message and stored in a list.

-Brendan