Join us on Discord!
You can help CodeWalrus stay online by donating here.

Code runs fine on TI Nspire emulator, but wont work on real hardware

Started by Strontium, April 27, 2015, 05:32:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Strontium

I am working on a roguelike for my TI Nspire CX. So far, everything works fine in the emulator, but on the calculator, I cannot use the arrow keys to move. Here is the code:

-- character info
playerx = 5
playery = 5
playerhp = 100

-- MONSTER CLASS THINGY
-- monster constructor
MonsterGen = {}
function MonsterGen:new(x, y, icon)
  o = {x = x, y = y, icon = icon}
  setmetatable(o, self)
  self.__index = self
  return o
end

-- move monster
function MonsterGen:move()
  -- temporary movement
  -- I will soon make this an algorythm to move towards the player
  self.x = self.x + 1
  self.y = self.y + 2
end

-- end monster class thingy

-- event handlers
function on.paint(gc)
  -- draw player stats
  gc:drawLine(260, 0, 260, 240)
  gc:drawString("HP", 265, 15)
  gc:drawString(tostring(playerhp) .. "/100", 265, 30)

  -- draw all the monsters
  for mono = 1, 2 do
    gc:drawString(monster[mono].icon, monster[mono].x * 20, monster[mono].y * 20)
  end
  -- draw the player
  gc:drawString('@', playerx * 20, playery * 20)
end

function on.arrowLeft()
  -- move player left
  playerx = playerx - 1
  turnTaken()
end

function on.arrowRight()
  -- move player right
  playerx = playerx + 1
  turnTaken()
end

function on.arrowUp()
  -- move player up
  playery = playery - 1
  turnTaken()
end

function on.arrowDown()
  -- move player down
  playery = playery + 1
  turnTaken()
end

-- perform various processes after player turn
function turnTaken()
  -- perform monster-ly processes
  for mono = 1, 2 do
    monster[mono]:move()
  end
end

monster = {}
monster[1] = MonsterGen:new(1, 1, 'k')
monster[2] = MonsterGen:new(3, 3, 'g')


I have no idea what is causing the movement to work on the emulator but not the calculator. At all. And I need help fixing it.

Edit: Ha! I figured it out. I forgot to call platform.window:invalidate() after each turn.

Woops.
  • Calculators owned: TI Nspire CX, HP Prime
  • Consoles, mobile devices and vintage computers owned: NES

Dream of Omnimaga

Glad you figured it out. :) I am curious about why the code would behave differently in the emulator than on the calculator otherwise, though... this screams like the emulator could use some fixes.
  • Calculators owned: TI-82 Advanced Edition Python TI-84+ TI-84+CSE TI-84+CE TI-84+CEP TI-86 TI-89T cfx-9940GT fx-7400G+ fx 1.0+ fx-9750G+ fx-9860G fx-CG10 HP 49g+ HP 39g+ HP 39gs (bricked) HP 39gII HP Prime G1 HP Prime G2 Sharp EL-9600C
  • Consoles, mobile devices and vintage computers owned: Huawei P30 Lite, Moto G 5G, Nintendo 64 (broken), Playstation, Wii U

Strontium

Yeah, I thought it was a bit weird when the emulator would update the graphics context without me explicitly telling it to. The last time I tried to do something in the emulator it didn't act that way.
  • Calculators owned: TI Nspire CX, HP Prime
  • Consoles, mobile devices and vintage computers owned: NES

Powered by EzPortal