* WalrusIRC

You need to have 5 posts and not be part of restricted usergroups in order to use the WalrusIRC embedded shoutbox. However, you can also access our IRC channel called #CodeWalrus via EFnet.

Author Topic: Code runs fine on TI Nspire emulator, but wont work on real hardware  (Read 596 times)

0 Members and 1 Guest are viewing this topic.

Offline Strontium

  • Full User
  • Join Date: Apr 2015
  • Location: CA
  • Posts: 220
  • Post Rating Ratio: +2/-2
  • hey
    • Unilunge
    • thelinethatmarkstheend
    • /u/thismarkstheend
    • Azmarok
    • View Profile
  • Gender: Female
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:

Code: [Select]
-- 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.
« Last Edit: April 27, 2015, 05:54:28 am by Strontium »


  • Calculators owned: TI Nspire CX, HP Prime
  • Consoles, mobile devices and vintage computers owned: NES
FRC 4711 represent

Offline DJ Omnimaga

  • Omni founder & CW co-founder
  • CodeWalrus Staff
  • Super User
  • Forum Maintenance
  • Original 5
  • CodeWalrus Supporter
  • *
  • Topic Management
  • Join Date: Nov 2014
  • Location: Quebec, Canada
  • Posts: 17425
  • Post Rating Ratio: +83/-4
    • dj_omnimaga
    • DJOmnimaga.music
    • @DJOmnimaga
    • dj_omnimaga
    • @DJOmnimaga
    • /u/DJ_Omnimaga
    • DJOmnimaga
    • 112/11286
    • @djomnimaga
    • @DJOmnimaga
    • View Profile
    • DJ Omnimaga music store
  • Gender: Male
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-73, TI-80 (broken), TI-81, TI-82, TI-83, TI-83+ (broken), TI-83+ (broken), TI-83+SE (broken), TI-84+, TI-84+CSE, TI-84+CE, TI-85, TI-86, TI-89T, TI-92, TI-Nspire, TI-Nspire CX, HP 39gII, HP Prime, Casio fx-7000G, fx-7400G+, fx-7700GE, fx-9750G+, fx-9750GII, fx-9860G, cfx-9850G, FX-1.0+, fx-CG10, fx-CP400
  • Consoles, mobile devices and vintage computers owned: Samsung i5510, Nexus 5, Atari 2600, Lynx, SMS, Game Gear, Genesis, Dreamcast, NES, SNES, N64, GCN, Wii, Wii U, GBA, DS, 3DS, PS2, PS3, PS4, PSP, PSVita, XBox 360, XBOne

Bandcamp|Reverbnation|Facebook|Youtube|Twitter
Retired Omnimaga admin (2001-11) and editor (2012-14)

Offline Strontium

  • Full User
  • Join Date: Apr 2015
  • Location: CA
  • Posts: 220
  • Post Rating Ratio: +2/-2
  • hey
    • Unilunge
    • thelinethatmarkstheend
    • /u/thismarkstheend
    • Azmarok
    • View Profile
  • Gender: Female
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
FRC 4711 represent

 


You can also use the following HTML or bulletin board code to share it on your page or forum signature!


Also do not forget to check our affiliates below.
Planet Casio TI-Planet Calc.news BroniesQC BosaikNet Velocity Games