Outside of the T.R.S. 80 Model I, Level I, I can't think of any BASIC language that would not let you use a double-sized array.
Here it is in BLITZ:
Global a[8,8] For i=0 To 7 For j=0 To 7 a[j,i]=15 Next Next |
Here is my attempt for PICO:
a={} for i=0,7 do for j=0,7 do a[j,i]=15 end end |
Is there a way to do this in PICO ?
EDIT: freds72 was faster than me^^.
PICO-8 uses parts of Lua for the Syntax. Google "lua 2d array":
https://www.lua.org/pil/11.2.html
Example:
a = {} for y=1,10 do a[y] = {} for x=1,10 do a[y][x] = 0 end end a[1][1] = 5 print(a[1][1]) |
EDIT²: To get every Value, you can use:
for y=1,#a do for x=1,#a[y] do print(a[y][x]) end end |
try this example program
function _init() w=new_grid(128,128) end function new_grid(_w,_h) local _t={} for i=1,_h do _t[i]={} for ii=1,_w do _t[i][ii]=15 end end return _t end function _draw() cls(0) for i=1,#w do for ii=1,#w[i] do rect(i,ii,i,ii,w[i][ii]) end end end |
Wow ! BIG thanks guys !!
I need to look these answers over carefully. Outside of Freds, most of this is definitely over my head. Old school programmer here you know. :)
And yes, I used the X*Y method to convert a 2-dimensional array to one in earlier code. It's just a hassle to do that. I really would like a true 2-dimensional array in my source without the multiplier.
Will look over these answers and try to learn what's going on in them.
While I've got you guys here, is there any way to read the current printing position of the PRINT cursor (X,Y) ? Most of this afternoon I've scoured PEEK memory and not coming up with it.
Actually it needs to be for 3-dimensions. Here's the code so far from following the examples above, also is not working:
scrn={} for i=0,3 do scrn[i]={} for j=0,127 do scrn[j]={} for k=0,127 do scrn[k][j][i]=5 end end end |
And am I going to run out of array space ? The array above would be 65536 elements in size if accepted.
Wait, got it working, the arrays are just not in the order I like. I wanted scrn[k][j][i]
scrn={} for i=0,3 do scrn[i]={} for j=0,127 do scrn[i][j]={} for k=0,127 do scrn[i][j][k]=k+j+i end end end for i=0,3 do for j=0,127 do for k=0,127 do if scrn[i][j][k]!=k+j+i then print"no" stop() end end end end |
This test shows that the array definitions are valid. Is there a memory limitation ?
is there any way to read the current printing position of the PRINT cursor (X,Y) ? |
http://pico-8.wikia.com/wiki/Memory
0x5f26-0x5f27: Print cursor (cursor()). 0x5f26=x, 0x5f27=y. |
function get_cursor() local x=peek(0x5f26) local y=peek(0x5f27) return x,y end cls(0) cursor(20,20) oldx, oldy = get_cursor() print("") print("world") cursor(oldx, oldy) print("hello") |
Augh ! It's no fair, Astorek86. I read that page about an hour ago - totally missed it. Phew ! Well, at least now I can write some decent debugging routines with print() with the values you listed.
You are also showing me something interesting, that it is possible to return =2= values from a function ?
Something I've never seen before ...
Also is there any way to transfer string or numeric array data to memory in one fast lump sum without using a loop like FOR/END ?
scrn="" for i=1 to 8192 scrn=scrn.."\0" end stringtomem(scrn,24576) -- memtostring(24576,8192,scrn) repeat flip() until btnp(4) |
[Please log in to post a comment]