How can I declare a 8bit Int?
Monkey Forums/Monkey Beginners/How can I declare a 8bit Int?
| ||
How can I declare a 8bit Int? |
| ||
You can't. Why did you want to? |
| ||
I got very big maps and it's save in bytecode (unsigned char) even in php I use bit's to save RAM |
| ||
MOBii wrote: I got very big maps and it's save in bytecode (unsigned char) even in php I use bit's to save RAM Store 4 chars (signed bytes) in an one monkey Int (really Int32). |
| ||
Well, you can't really use bytes/8-bit integers directly, but you can use 'Streams' and the 'DataBuffer' class to read and write bytes. In the case of streams, you'd use 'WriteByte:Void(Value:Int)', and 'ReadByte:Int()'. And for DataBuffers, you can use 'PokeByte:Void(Address:Int, Value:Int)', and 'PeekByte:Int(Address:Int)'. Streams should generally be accessed 'virtually' via the 'Stream' class, which can be found in the 'brl.stream' module. The 'DataBuffer' class is generally just dealt with normally, and can be found in the 'brl.databuffer' module. One of the cons about 'DataBuffers' is that they're slow on platforms like Android (At least with older devices), but they will save space in the long-run. That being said, for my tile-map implementation(s), for example, I tend to just write a simple agnostic interface, and use the preprocessor to describe if I'm using 'DataBuffers' or Integer arrays. Generally speaking, I stick to 'DataBuffers' for most targets, but in case I need an alternative, I have the option. Here's some pages which might interest you (These are available through 'Ted', and other IDEs): * The online documentation for 'brl.databuffer'. * The online documentation for 'brl.stream'. * The online documentation for 'brl.datastream'. When in doubt about a class or command, you can always hit F1. EDIT: As nikoniko said, you could always use bitwise shifting, so you can just work with an integer array. All Monkey targets are supposed to be little-endian. (Although, some people have been having endian problems with the 'Flash' target) If you need endian conversion commands, or just an example of bitwise shifting, I'll point you to my 'byteorder' module. |
| ||
Edit: I am currently in a other programming environment that only take 1 statement a row and can't write parentheses in the If I can't write If like this: If A = 1 And (B = 1 or C = 1) Print "OK" So I need to write like this or split the If to 2 If A = 1 And B = 1 or A = 1 And C = 1 Print "OK" If A = 1 And B = 1 Print "OK" If A = 1 And C = 1 Print "OK" I am totally green in Monkey X still trying figure out if this is what I want instead of my other environment For me when I can't do this and I can't do that, make me irritated I am trying not to do the same mistake I did by getting my currently environment, by testing and see the language and it's environments flaws I invested $360 on my currently environment, I been working on a project for 4 month and I am not sure how much I need to compromise for complete my project. I can't do this and I can't do that. I am more in making application than game, but to have the freedom like Monkey X to publish in any platform would be great. |
| ||
Thank thee both ImmutableOctet(SKNG) and nikoniko My biggest map is in a MySQL database at the moment, but with my map editor I can make smaller and local maps I like the idea make 4 unsigned char of the int, but it feel little wrong when I need to extract the numbers for every time I use em, but probably have no impact on performance anyhow Thank the ImmutableOctet(SKNG) I get little more happy now |
| ||
If 0 And 1 or 1 Print "OK" I am a idiot, and I am very sorry I was thinking it was working like this: If 0 And (1 or 0) Print "OK" Correct Example: If A = 1 And (B = 1 or C = 1) Print "OK" My currently environment I had to write: If A = 1 And B = 1 or A = 1 And C = 1 Print "OK" To see the code in the editor make me understand the problem! |
| ||
Edited: If 0 And 0 or 1 Print "This is NOT ok in my mind" I am a idiot, and I am very sorry I was thinking it If was working always like this: If A = 1 And (B = 1 or C = 1) Print "OK" If I say this in RL: I want a Apple and a Kiwi or a Banana I can get a Kiwi or a Banana it doesn't matter but I want a Apple Silly me! To see the code in a real editor make me understand the problem! |
| ||
Happens to me often aswell, when in try to explain my problem, then i often find the solution :) And then i made useless spam to the forums hehe |