# Maximum SDF value?

## Recommended Posts

Hello,

Perhaps this is an obvious question, but I can't find the answer on these fora or the documentation, so: What is the maximum value of an SDF?

Thanks

##### Share on other sites

SDFs are 8-bit unsigned integers, so they can store numbers in the range [0-255].

Thank you.

##### Share on other sites

Originally Posted By: Niemand
SDFs are 8-bit unsigned integers, so they can store numbers in the range [0-255].
That's odd. I thought the maximum was 250.
##### Share on other sites

That would be silly, since 2^8-1 = 255, and to my knowledge Jeff enforces no such silliness.

##### Share on other sites

You're right. I found the SDF range in the BoA editor documentation appendix:

Quote:
void inc_flag(short a,short b,short how_much) - Changes SDF(a, by how_much (which can be negative). Note the legal range of values for a flag is 0..255.

I was probably thinking of the original (shareware) version of BoE, where certain special one-shot encounters could set an SDF to 250. Though those SDFs probably had a range of 0-255 too; the original BoE scenario editor documentation doesn't say.

##### Share on other sites

You can join two SDFs to have values up to 255*255 = 65,535.

##### Share on other sites

Indeed, but it takes a bit of care. (The linked to method actually stores signed 16-bit numbers, rather than unsigned, since Avernumscript only has signed int variables.) One could implement arbitrary precision arithmetic if one really wanted to, I think, but I can't imagine it being at all practical.

##### Share on other sites

255*255 = 65,535
255*255 is actually 65,025. You should be multiplying 256*256 instead: the number of possible values, not the maximum value.
##### Share on other sites

Originally Posted By: Niemand
That would be silly, since 2^8-1 = 255, and to my knowledge Jeff enforces no such silliness.
Still need to be careful, there are some odd gotchas in BoA. For instance, one usually assumes that strings in scripting languages based on C can be 255 characters long (not including the null character). But in BoA, they can only be 254 characters (been a while since I tested this, but I'm pretty sure it's true, despite documentation saying otherwise).
##### Share on other sites

Yes, but in this case I know with good certainty that SDFs work sensibly. (As I noted, it wouldn't have been totally surprising if Jeff had done something odd here, but he didn't.)

You are correct about the maximum string length. I really don't quite know what Jeff was thinking here, particularly since, in a rare fit of modernity, he doesn't put the strings into fixed sized buffers anyway. (In fact, he even uses operator new[] to allocate the buffers, rather than direct malloc![^1]) It's possible that the limitation to 254 characters stems from mistakenly writing >=255 (when checking for disallowed lengths), rather than just >255. Another possibility is that he had the number 255 in mind rather that 256 as the base as a result of having to deal with Pascal strings.

[^1]: For anyone curious, there's enough of the script system left in the editor in global.h and EdParser.cpp to see how a lot of it works. The implementation is actually complete enough to run simple scripts that only do arithmetic and flow control.

##### Share on other sites

I think we eventually came to the conclusion that 254 was the result of having 256 characters but having "begin" and "end" be two of the characters. (The open quotes and close quotes actually count as characters, so "Run!" would be six characters, not four.)

Would explain the otherwise arbitrary 38 on the text bubbles (was actually 40, but includes the quotes).

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
×
• Create New...