Log In  
Log In  

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 ?

P#55554 2018-08-23 15:45 ( Edited 2018-08-23 21:26)

for ...
 for ...
  a[i+8*j]=15
 end
end
— or
for ...
 a[i]={}
 for ...
  a[i][j]=15
 end
end
P#55559 2018-08-23 16:19 ( Edited 2018-08-23 20:19)

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
P#55561 2018-08-23 16:22 ( Edited 2018-08-23 20:26)

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
P#55562 2018-08-23 16:23 ( Edited 2018-08-23 20:23)
:: dw817

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.

P#55565 2018-08-23 16:41 ( Edited 2018-08-23 20:45)
:: dw817

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.

P#55568 2018-08-23 16:50 ( Edited 2018-08-23 20:50)
:: dw817

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 ?

P#55569 2018-08-23 16:54 ( Edited 2018-08-23 20:55)

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")
P#55570 2018-08-23 16:57 ( Edited 2018-08-23 20:57)
:: dw817

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 ...

P#55571 2018-08-23 17:06 ( Edited 2018-08-23 21:06)
:: dw817

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)
P#55574 2018-08-23 17:26 ( Edited 2018-08-23 21:27)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-05-21 08:35 | 0.020s | 4194k | Q:33