Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

TIC-80

Fantasy computer for making, playing and sharing tiny games. · By Nesbox

Why does my code crash TIC-80?

A topic by Martsadas created Sep 04, 2021 Views: 356 Replies: 2
Viewing posts 1 to 3

For some reason when i run this code TIC-80 crashes

-- title:  game title
-- author: game developer
-- desc:   short description
-- script: moon
ticks = 1
cur =
 x: 2
 y: 0
 rot: 1
 piece: 1
 color: 1
PIECES = {
 {
  {{0,1,0,0}, {0,1,0,0}, {0,0,0,0}, {0,1,0,0}},
  {{1,1,1,0}, {0,1,1,0}, {1,1,1,0}, {1,1,0,0}},
  {{0,0,0,0}, {0,1,0,0}, {0,1,0,0}, {0,1,0,0}},
  {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}},
 },
}
export TIC=->
 cls 0
  for i = 0,11
   for j = 0,16
    spr mget(i, j), 72+i*8, j*8
 for i = 1,4
  for j = 1,4
   if PIECES[cur.piece][j][1][i] == 1
    spr cur.color, 72+(cur.x + i)*8, (cur.y + j)*8
 if ticks % 15 == 1
  if collide(cur.x, cur.y+1)
   for i = 1,4
    for j = 1,4
     if PIECES[cur.piece][j][1][i] == 1
      mset i+cur.x, j+cur.y, cur.color
  cur.y = 1
 else
  cur.y += 1
 ticks += 1
export collide = (x, y) -> 
 for i = 1,4
  for j = 1,4
   if PIECES[cur.piece][j][1][i] == 1
    if mget(x+i, y+j) > 1
     return true
 return false
Developer

Just copypasted, fixed tabs near `cls 0` and got this


fixed code

-- title:  game title
-- author: game developer
-- desc:   short description
-- script: moon
ticks = 1
cur =
 x: 2
 y: 0
 rot: 1
 piece: 1
 color: 1
PIECES = {
 {
  {{0,1,0,0}, {0,1,0,0}, {0,0,0,0}, {0,1,0,0}},
  {{1,1,1,0}, {0,1,1,0}, {1,1,1,0}, {1,1,0,0}},
  {{0,0,0,0}, {0,1,0,0}, {0,1,0,0}, {0,1,0,0}},
  {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}},
 },
}
export TIC=->
 cls 0
 for i = 0,11
  for j = 0,16
   spr mget(i, j), 72+i*8, j*8
 for i = 1,4
  for j = 1,4
   if PIECES[cur.piece][j][1][i] == 1
    spr cur.color, 72+(cur.x + i)*8, (cur.y + j)*8
 if ticks % 15 == 1
  if collide(cur.x, cur.y+1)
   for i = 1,4
    for j = 1,4
     if PIECES[cur.piece][j][1][i] == 1
      mset i+cur.x, j+cur.y, cur.color
  cur.y = 1
 else
  cur.y += 1
 ticks += 1
export collide = (x, y) -> 
 for i = 1,4
  for j = 1,4
   if PIECES[cur.piece][j][1][i] == 1
    if mget(x+i, y+j) > 1
     return true
 return false

Thanks!