Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
20 May, 2013, 18:55:48 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Platform-specific Problem -  (Read 796 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Reo
LV3 Member (Next: 100)
***
Offline Offline

Gender: Male
Last Login: Today at 01:06:37
Date Registered: 28 September, 2011, 03:40:56
Location: Pennsylvania
Posts: 63

Topic starter
Total Post Ratings: +14

View Profile
« on: 13 October, 2011, 21:02:55 »
0

I'm creating a simple tile-based game similar to Chip's Challenge in LUA, and I'm having a strange problem. I mainly test my game on the TI-Nspire CAS Student Software that came with the calculator, and my game works fine. However, when I transfer the program to my calculator and run it, a few bad things happen:

1. The level-area, composed of a solid background color with two object layers and the player, doesn't draw right. It only draws the player and the background.
2. When I attempt to move the player, the script crashes with an error in the collision detection functions saying that it's trying to compare my player's position to nil. What it should compare it to is the result of an expression that returns the object ID of an object at a position in the "level table" (where objects are stored) specified by a function argument.

I've figured this much out: the level loads right, because a function called in the level initiation function that scans the room for a certain number of objects works. I just don't know where to go after that. Is there any platform-specific difference that I'm missing that's stumping me?
I'd rather not share my source code unless necessary because it's very messy. If needed, just tell me.
Logged
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 18:20:31
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #1 on: 13 October, 2011, 23:29:22 »
0

Normally, it should work on both the platforms without a problem.
There might be issues with color though, so be sure to use setColorRGB.

The only way I can help with 2 is that you give me some bits of code, so I can look into it.
Logged

adriweb
Editor
LV9 Veteran (Next: 1337)
*
Offline Offline

Gender: Male
Last Login: Today at 00:38:33
Date Registered: 13 April, 2011, 18:42:59
Location: South of France
Posts: 1196


Total Post Ratings: +185

View Profile WWW
« Reply #2 on: 14 October, 2011, 00:11:31 »
0

Here are several things you might want to pay attention to :

- Don't use platform.gc(): as your standard GC context (only use the on passed in the on.paint(gc) event).
- Make sure you refresh the drawing buffer often enough. That might be the real problem of yours, here. Actually, the software refreshes constantly, contraty to the device, which refrehes only when needed or when it's asked. So make sure that when you want to draw something and update the screen consequently, call platform.window:invalidate().


About your 2nd question, the code would indeed be needed...

Good Luck Wink
« Last Edit: 14 October, 2011, 00:13:46 by adriweb » Logged


TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation
Reo
LV3 Member (Next: 100)
***
Offline Offline

Gender: Male
Last Login: Today at 01:06:37
Date Registered: 28 September, 2011, 03:40:56
Location: Pennsylvania
Posts: 63

Topic starter
Total Post Ratings: +14

View Profile
« Reply #3 on: 14 October, 2011, 02:28:00 »
0

- Don't use platform.gc(): as your standard GC context (only use the on passed in the on.paint(gc) event).
- Make sure you refresh the drawing buffer often enough. That might be the real problem of yours, here. Actually, the software refreshes constantly, contrary to the device, which refreshes only when needed or when it's asked. So make sure that when you want to draw something and update the screen consequently, call platform.window:invalidate().
I only use platform.gc() in functions that are called only during on.paint, though I use platform.gc() most of all because I've split my drawing functions into groups. I also refresh my screen every 0.1 seconds, and I believe that this should be enough.
Really, I believe that the first problem is caused by the second. It's like the table is totally gone after the level init function, and I have no idea why.
There's no color issues between platforms either; I forgot to mention that I develop this on for a CX with the CX student software. So if anything there'll be issues on a regular nspire which I'll have to solve later.
Here's some code where I think there are problems, with some comments.

startLevel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function startLevel(num, keepkeys, startx, starty) --Pass this function a level number, and it'll warp the player.
if layer0[num]==nil then --If the level doesn't exist, the player must have won.
pause=1 --However, I have no screen for this yet, so for now it
else --just pauses.
if keepkeys == 0 then --If I somehow want to start the level with keys from the
keys = {0, 0, 0, 0} --previous.
end
if startx > 0 then --Assuming that if you specify one starting coord, both are used.
playerx = startx
playery = starty
else
playerx = startpos[num][1] --If none specified, get them from a table.
playery = startpos[num][2]
end
levelsize = math.sqrt(#layer0[num]) --This works because levels are completely square.
local area = (levelsize*levelsize)
level1 = {} --Table where the first level layer will be contained.
level2 = {} --Table where the second level layer will be contained.
for i=1, area do
level1[i] = layer0[num][i] --Function that copies the original level data
level2[i] = layer1[num][i] --to the two layers for gameplay. Possible point
end --of interest.
backgroundcolor = {mapcolor[num][1],mapcolor[num][2],mapcolor[num][3]} --Each level can have a unique background color.
levelnum = num --
maxbluekeys = 0
for i=1, area do --Scans the level for blue key fragments and
if level2[i] == 6 then --totals them because all must be collected
maxbluekeys = maxbluekeys + 1 --to create a blue key.
end
end
camerax = 0
cameray = 0 --Reset the camera position
fixCamera() --and move it to the player.
end
end

collisionCheck

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function collisionCheck(x, y)
local compare = level1[(y*levelsize)+(x+1)] --Object ID of this position in layer 1. <  What is said to be "nil" when game crashes
if compare > 0 then --If it's above 0, it's a flavor of normal solid block.
return true --Returning true says "Yes, there will be a collision."
elseif compare == 0 then --If nothing's there,
return false --there's no collision.
elseif compare == -1 then
if keys[1] > 0 then --Here is where we have negative block IDs,
keys[1] = keys[1]-1 --where blocks determine their solidity
level1[(y*levelsize)+(x+1)] = 0 --based on logic.
return true --This is a yellow key door.
else
return true
end
elseif compare == -2 then --Red key door.
if keys[2] > 0 then
keys[2] = keys[2]-1
level1[(y*levelsize)+(x+1)] = 0
return true
else
return true
end
elseif compare == -3 then --Green key door. Green keys last until level end.
if keys[3] > 0 then
level1[(y*levelsize)+(x+1)] = 0
return true
else
return true
end
elseif compare == -4 then --Blue key door. Found in pieces that can
if keys[4] > maxbluekeys-1 then --be put together, and will last until the
level1[(y*levelsize)+(x+1)] = 0 --end of the level.
return true
else
return true
end
else --If nothing else, assume it's false for no reason.
return false
end
end

EDIT: I disabled collision detection by always evaluating compare as "0". If I move around to the left side of the level, I can get some garbage tiles (tiles that don't draw in the right place) to draw in one row, and they disappear when I leave that row. This mystifies me.
Here's a screenshot of what it looks like when it's working on the PC:

Here's a picture of the odd occurence I just described on the calculator:

The red key value is actually a measure of the area of the level because I hacked up the drawing function for it to debug. The value on the calculator is actually one less than on the PC.
« Last Edit: 14 October, 2011, 03:51:32 by Reo » Logged
NecroBumpist
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Total Post Ratings: +9

View Profile
« Reply #4 on: 14 October, 2011, 03:37:36 »
0

Functions based inside gc (ie gc:drawRect(), gc:drawString(), etc) only work if they are called indirectly from within on.paint().
And as said earlier, you have to refresh the screen yourself, so either set a timer, or do it manually.

Examples:

1
2
3
4
5
6
7
8
9
10
local ggc; -- global graphics context

function on.paint(gc)
gcc = gc;
end

function on.enterKey()
gcc:drawString("Herp", 0, 0, "top");
end

That will not work. This will.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
local extra;

function on.paint(gc)
-- do normal painting

if extra then
extra(gc);
extra = nil;
end
end

function on.enterKey()
extra = function(gc) gc:drawString("Herp", 0, 0, "top"); end

platform.window:invalidate();
end

You're problem for 2 is most likely either you're passing the wrong arguments, or your accessing part of the table that doesn't exist (out of bounds), causing it to return a nil value, which is later compared to something else, like a number. Lua doesn't allow this.

Either read through the calling function, or add some conditional code to make sure the inputs are safe.

The error's line number would be appreciated as well.
« Last Edit: 14 October, 2011, 03:39:07 by NecroBumpist » Logged

Developing Lua scripts for the NSpire ?
Check out the Necrotorium
Need a few routines to run faster ? Checkout the MODS Lua Assembly Toolkit.
Need to save space for your scripts ? Checkout LuaSrcDiet
Reo
LV3 Member (Next: 100)
***
Offline Offline

Gender: Male
Last Login: Today at 01:06:37
Date Registered: 28 September, 2011, 03:40:56
Location: Pennsylvania
Posts: 63

Topic starter
Total Post Ratings: +14

View Profile
« Reply #5 on: 14 October, 2011, 04:05:41 »
0

What concerns me is that this works absolutely fine on the PC; both problems do not occur on the PC. What I'm wondering is exactly what varies between each platform that's causing my issue.

Also, as far as I know, I'm drawing correctly. Here's an example of some of my drawing code:

on.paint

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function on.paint(gc)
if title == 0 then
drawHUD()
drawLayer1()
drawPlayer()
drawLayer0()
if pause == 1 then
gc:setFont("sansserif","r",48)
gc:setColorRGB(150,0,0)
gc:drawString("Paused",159,106,"middle")
end
else
drawTitle()
end
timer.start(0.1)
end

drawPlayer

1
2
3
function drawPlayer()
platform.gc():drawImage(playersprite,originx+((playerx-camerax)*16),originy+((playery-cameray)*16))
end

Though some of the tiles fail to draw right on the calculator, everything else draws on both platforms.

Here's a screenshot of the crash I'm getting:
Logged
NecroBumpist
LV4 Regular (Next: 200)
****
Offline Offline

Gender: Male
Last Login: 04 November, 2012, 07:02:18
Date Registered: 18 August, 2011, 05:44:50
Location: In my IDE, programming shit
Posts: 129


Total Post Ratings: +9

View Profile
« Reply #6 on: 14 October, 2011, 04:54:26 »
0

Well then, your problem is that the leve1 table simply doesn't have what you're looking for in it.
So display the answer of the expression you're using (y * levelsize+x+1) and see if that looks wrong.
That value is simply not in the table, because the compare value is nil.
Logged

Developing Lua scripts for the NSpire ?
Check out the Necrotorium
Need a few routines to run faster ? Checkout the MODS Lua Assembly Toolkit.
Need to save space for your scripts ? Checkout LuaSrcDiet
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 17:49:32
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50205


Total Post Ratings: +2611

View Profile WWW
« Reply #7 on: 14 October, 2011, 05:08:18 »
0

Question, what version of computer software do you have and what OS version does your calc run on? For example, from OS 3.0.2 to 3.1.0 some Lua functions stopped working and new ones got added. I do not know which ones, though.

Also welcome here. This game also looks nice so far too.
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Reo
LV3 Member (Next: 100)
***
Offline Offline

Gender: Male
Last Login: Today at 01:06:37
Date Registered: 28 September, 2011, 03:40:56
Location: Pennsylvania
Posts: 63

Topic starter
Total Post Ratings: +14

View Profile
« Reply #8 on: 14 October, 2011, 06:49:56 »
0

Question, what version of computer software do you have and what OS version does your calc run on? For example, from OS 3.0.2 to 3.1.0 some Lua functions stopped working and new ones got added. I do not know which ones, though.
They were both on 3.0.2, until I updated the computer software to 3.1.0 to see if something changed.

Also welcome here. This game also looks nice so far too.
Thank you.

Well then, your problem is that the leve1 table simply doesn't have what you're looking for in it.
So display the answer of the expression you're using (y * levelsize+x+1) and see if that looks wrong.
That value is simply not in the table, because the compare value is nil.
I'll try this out later.
Logged
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 17:49:32
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50205


Total Post Ratings: +2611

View Profile WWW
« Reply #9 on: 14 October, 2011, 07:29:24 »
0

Ok, then the OS is not the issue. I remember the emulator was not really a real emulator, though, and therefore it did not emulate the real machine correctly. In fact the student software cannot even run Ndless nor Ndless games when we use the versions with OS 2.x. From what I remember, games like PacMan and Nyan Cat were not even full screen or some stuff did not show up.

The best solution would be to use Goplat's emulator, but then the problem is that you won't be able to see the color, as it emulates the regular TI-Nspire, not the color one. http://www.omnimaga.org/index.php?topic=6763.msg156233#msg156233

Texas Instruments just fails epically at keeping their emulation accurate. We had the same problem with their 83+ emulators. The worst part is that the 84+ emulator that came built in older Nspire models did not emulate the 84+ correctly either. X.x
« Last Edit: 14 October, 2011, 07:30:39 by DJ_O » Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Jim Bauwens
Lua! Nspire! Linux!
Editor
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 18:20:31
Date Registered: 28 February, 2011, 22:32:12
Location: Belgium
Posts: 1733


Total Post Ratings: +180

View Profile WWW
« Reply #10 on: 14 October, 2011, 09:33:23 »
0

Quote

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function on.paint(gc)
if title == 0 then
drawHUD()
drawLayer1()
drawPlayer()
drawLayer0()
if pause == 1 then
gc:setFont("sansserif","r",48)
gc:setColorRGB(150,0,0)
gc:drawString("Paused",159,106,"middle")
end
else
drawTitle()
end
timer.start(0.1)
end

drawPlayer

1
2
3
function drawPlayer()
platform.gc():drawImage(playersprite,originx+((playerx-camerax)*16),originy+((playery-cameray)*16))
end

I see that you are using platform.gc(). This is not recommended, because its not the same as the gc passed to on.paint (it is not yet initialized).
The solution to this is to pass gc as parameter of the function:

1
2
3
4
5
6
7
8
9
10
11
12
function on.paint(gc)
    ...

    drawPlayer(gc)

    ...
end

function drawPlayer(gc)
    gc:drawImage(playersprite,originx+((playerx-camerax)*16),originy+((playery-cameray)*16))
end

What I also see is that when you copy layer0 into level1 and level2, you use this:

1
2
3
4
5
for i=1, area do
level1[i] = layer0[num][i] --Function that copies the original level data
level2[i] = layer1[num][i] --to the two layers for gameplay. Possible point
end
I assume layer0[num][ i] is a table? If so, this means that level1[ i] is a reference to it, not a copy.
This way, if something happens to layer0 it will effect level1 and opposite. I don't know if this is intentional, but you need to watch out with these things.

Also, I suggest you too look at the way Levak's sudoku (http://tiplanet.org/forum/archives_voir.php?id=3550&play=) handles drawing to the screen. It makes having multiple screens (intro, game, menu) a piece of cake. I don't say you have to copy code directly, but it is a huge help in the long term, as it makes your code more clear and easy to handle.
« Last Edit: 14 October, 2011, 09:34:15 by jimbauwens » Logged

adriweb
Editor
LV9 Veteran (Next: 1337)
*
Offline Offline

Gender: Male
Last Login: Today at 00:38:33
Date Registered: 13 April, 2011, 18:42:59
Location: South of France
Posts: 1196


Total Post Ratings: +185

View Profile WWW
« Reply #11 on: 14 October, 2011, 13:20:59 »
0

About that gc thing, jim'post is exactly what to read and learn.

The reason platform.gc() is not recommended is that it's actually going to be gone (kind of) in future version of the lua API.
So please, use the gc passed by on.paint(gc), as Jim showed you.

the reason platform.gc() was created and made available in the first place was to be able to access some primary functions like string length etc. (getStringWidth...) before the on.paint event....
« Last Edit: 14 October, 2011, 13:22:13 by adriweb » Logged


TI-Planet.org co-admin.
TI-Nspire Lua programming : Tutorials  |  API Documentation
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.44 seconds with 31 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.