Garrulous Glaahk Handyman Posted January 14, 2011 Posted January 14, 2011 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 Quote
Well-Actually War Trall Niemand Posted January 14, 2011 Posted January 14, 2011 SDFs are 8-bit unsigned integers, so they can store numbers in the range [0-255]. Quote
Easygoing Eyebeast The Mystic Posted January 14, 2011 Posted January 14, 2011 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. Quote
Well-Actually War Trall Niemand Posted January 14, 2011 Posted January 14, 2011 That would be silly, since 2^8-1 = 255, and to my knowledge Jeff enforces no such silliness. Quote
Easygoing Eyebeast The Mystic Posted January 14, 2011 Posted January 14, 2011 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. Quote
Well-Actually War Trall Ishad Nha Posted January 18, 2011 Posted January 18, 2011 You can join two SDFs to have values up to 255*255 = 65,535. Quote
Well-Actually War Trall Niemand Posted January 18, 2011 Posted January 18, 2011 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. Quote
Understated Ur-Drakon Celtic Minstrel Posted January 18, 2011 Posted January 18, 2011 Originally Posted By: Ishad Nha 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. Quote
Easygoing Eyebeast Dintiradan Posted January 19, 2011 Posted January 19, 2011 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). Quote
Well-Actually War Trall Niemand Posted January 19, 2011 Posted January 19, 2011 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. Quote
Magnificent Ornk Kelandon Posted January 19, 2011 Posted January 19, 2011 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). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.