Thread: My code is crashing pipmak, but why?
Status: Alpha
Brought to you by:
cwalther
From: syxified <syx...@ya...> - 2009-09-09 20:01:18
|
The answer to this will probably be very simple, since I am no coding pro and mostly have just fumbled my way through this, but if anyone could help me out, it would be much appreciated. I'm working on a game, and at the moment I'm focused on implementing an inventory overlay node that can be called globally/toggled with the "i" key. Of course, all the individual item names are going to have to be little patches that I will lay handles on to make them selectable, etc. So I'm trying to get it so it arranges those patches (items in inventory) on the overlay node sequentially based on if they are in the players possession or not. I just introduced a 'for' loop into the onkeydown handler to check the array of patches, and those which are found to be true in the inventory get moved so they are in a decending order visually on the page. However, that for loop keeps crashing pipmak the moment I hit the "i" button. Any help would be much appreciated. So, here is the code i have, first is Main, second is node 99, which is the inventory overlay node: version (0.27) title "Dark Heart Test" startnode (2) state.invenOpen = false state.Abacus = true state.Bone = true state.Corpse = true readState = false onkeydown( function(key) if key == string.byte("i") then if state.invenOpen == false then pipmak.overlaynode(99, dontsave) state.invenOpen = true itemDepth = 90 itemOffset = 20 for i=1, 3 do --change that 3 to the item table size currentItem = itemObjectTable[i] currentItem:move{y = itemDepth} itemDepth = itemDepth + itemOffset end return true else inventoryNode:closeoverlay() state.invenOpen = false return false end end end ) --this is the inventory node 99 scrollObject = pipmak.getimage("../99/justScroll.bmp") scrollWidth, scrollHeight = scrollObject:size() itemObject = pipmak.getimage("../99/justItem.bmp") itemWidth, itemHeight = itemObject:size() itemAbacus = pipmak.getimage("../99/itemAbacus.bmp") itemBone = pipmak.getimage("../99/itemBone.bmp") itemCorpse = pipmak.getimage("../99/itemCorpse.bmp") itemAllTable = { itemAbacus, itemBone, itemCorpse } panel { scrollObject, relx = .5, rely = .5, absx = -(.5 * scrollWidth), absy = -(.5 * scrollHeight) } inventoryNode = pipmak.thisnode() itemDepth = 40 itemOffset = 20 itemLocationTable = { itemDepthAbacus, itemDepthBone, itemDepthCorpse } itemObjectAbacus = patch { x = (.5 * scrollWidth) - (.5 * itemWidth), y = itemDepth, w = itemWidth, h = itemHeight, visible = state.Abacus, image = itemAllTable[iter], } iter = iter + 1 itemObjectBone = patch { x = (.5 * scrollWidth) - (.5 * itemWidth), y = itemDepth, w = itemWidth, h = itemHeight, visible = state.Bone, image = itemAllTable[iter], } iter = iter + 1 itemObjectCorpse = patch { x = (.5 * scrollWidth) - (.5 * itemWidth), y = itemDepth, w = itemWidth, h = itemHeight, visible = state.Corpse, image = itemAllTable[iter], } iter = iter + 1 itemObjectTable = { itemObjectAbacus, itemObjectBone, itemObjectCorpse } itemStateTable = { state.Abacus, state.Bone, state.Corpse } --THAT'S IT! Thanks in advance! ~Matt -- View this message in context: http://www.nabble.com/My-code-is-crashing-pipmak%2C-but-why--tp25372235p25372235.html Sent from the pipmak-users mailing list archive at Nabble.com. |
From: Christian W. <cwa...@gm...> - 2009-09-10 11:24:57
|
syxified wrote: > I just introduced a 'for' loop into the > onkeydown handler to check the array of patches, and those which are found > to be true in the inventory get moved so they are in a decending order > visually on the page. However, that for loop keeps crashing pipmak the > moment I hit the "i" button. Quick answer before I have time to actually test your code or show you a better solution: You can't store the patch objects from node 99 in global variables and use them before node 99 is entered or after node 99 is left. These objects are (re-)created when their node is entered and are only valid as long as the node is displayed. Arranging the patches should be done in an onenternode handler of node 99 (or create them at the correct location in the first place). That said, any possibility to crash Pipmak using Lua scripting is a bug and I will look into it. Thanks for the report. -Christian |
From: syxified <syx...@ya...> - 2009-09-10 16:03:24
|
Well, I'm closing in on it. Based on your advice I put those tables in an enternode handler. Now if I do startnode(99) and use the "i" toggle key, it does arrange the items based on the table of which are true (i.e. which the player has collected). However, when I try to do that while on some other dummy node I created the pipmak window simply vanishes and I'm booted out of the system. I'm going to try putting that arrangement code in 99 rather than main, which I believe is what your suggestion is, and cross me fingers. ~Matt -- View this message in context: http://www.nabble.com/My-code-is-crashing-pipmak%2C-but-why--tp25372235p25385613.html Sent from the pipmak-users mailing list archive at Nabble.com. |
From: syxified <syx...@ya...> - 2009-09-10 16:14:38
|
...and, that did it! Putting that 'for' loop into the inventory node on the enternode handler rather than in main.lua when placing the overlay node did it. When I was imagining how it would work, I pictured it overlaying all those individual things (which I guess I could have done by making a ton of panel nodes, but I should have thought of the inventory node as all its own picture. However, if you still want to show me a better way of doing this, I would not at all be surprised if it could be done far more efficiently than I am in stumbling my way through it. BTW, while I've got you, I wanted to toss you a quick compliment on the reference guide. The writing is very succinct and easy to understand, and the conventions you use for type style to show what things are in the code makes perfect sense, far more than most guides on coding. Cheers! ~Matt -- View this message in context: http://www.nabble.com/My-code-is-crashing-pipmak%2C-but-why--tp25372235p25386053.html Sent from the pipmak-users mailing list archive at Nabble.com. |