Peek / Poke newbie
Blitz3D Forums/Blitz3D Beginners Area/Peek / Poke newbie
| ||
H! I don't understand the peek poke function :S I have this code: bnkTest=CreateBank(2) PokeShort bnkTest,0,2044 PokeShort bnkTest,1,355 Print PeekShort(bnkTest,0) Print PeekShort(bnkTest,1) FreeBank bnkTest WaitKey And the result I get is 25596 355 But I want 2044 355 Why is he changing the first number ? Thanks |
| ||
A short is two bytes long, so the second PokeShort is overwriting one of the bytes occupied by the first. The offset is always in bytes regardless of whether you're poking a byte, short or long, so you need to multiply your offsets by 1, 2 or 4 bytes to avoid overwriting. |
| ||
ow now i understand it. A short(65535) : 0 2 4 etc A int(2147483647): 0 4 8 etc Thanks :) |
| ||
How would I poke something to a bank other than a number, such as a string, type, array, image, ect? |
| ||
How would I poke something to a bank other than a number, such as a string, type, array, image, ect? Check your help docs for the following commands: PokeShort, PokeInt, PokeByte, PokeString, and the resulting Peek functions.As far as images, sounds, etc, most of those are generally described with 'handles', which are essentially just int's.. so you can take it from there :) |
| ||
How would I poke something to a bank other than a number, such as a string, type, array, image, ect? For images, you must make your own 'raw' format then. Since you have access to imagebuffers you can copy data between banks and images.. you can't access soundbuffers atm, so that's a nono .. For those other formats, you have to 'code' native variables yourself.. A string, is ofcourse a number of ascii values .. so, if you want to store the word "Blitzbasic" then you need a bank with the size of 10 .. and each byte holds the ascii value of each of those characters.. Naturally.. you can't store more than those 10 then.. there's no bounds-checking on banks. @ win98se orso this might lead to a serious crash! If you want to store a string in a bank, then you prolly have to make your own String2Bank(bank,s$) function, where the function checks the bounds for you.. (and optionally resizes the bank!) An array of bytes for example, is just the bank with the banksize being the number of elements.. An array of ints (handles are ints!) is a bank with the banksize being the amount of elements / 4 .. An array of types .. dunno, I'm not the type-type .. question is why you would want to put a type into a bank anyway .. If you want to work with banks, you definitly want a monitor: http://www.blitzbasic.co.nz/Community/posts.php?topic=29266 |
| ||
Well, I want to have a list of types stored in a bank. I asked about other things because I want to learn as much about Blitz as I possibly can. |
| ||
The easiest option for storing types are arrays (for me anyway). There are many topics related to arrays of types. And you cannot ever miscalculate the offset when using arrays. A quick example: ; Create a window of size 800x600 Graphics 800, 600, 0, 2 ; Create the type and add fields to it Type MyType Field x%, y% End Type ; Create an array with the name "MyArray", tell it to hold pointers to the type "MyType" ; (as you would tell an array to hold strings: Dim MyArray$(10)) and give it 11 indexes (0 - 10) Dim MyArray.MyType(10) ; Now create all type instances and put their pointer into the array For i = 0 To 10 MyArray(i) = New MyType Next ; Put some data into it For i = 0 To 10 MyArray(i)\x% = i MyArray(i)\y% = i * 2 Next ; Print all data For i = 0 To 10 Print i + ": " + MyArray(i)\x% + ", " + MyArray(i)\y% Next ; Wait for a keypress to close the window WaitKey() End |