Log In  

can someone tell me why I am running out of memory?

Cart #jajefutayu-1 | 2019-07-18 | Code ▽ | Embed ▽ | No License

@Catatafish I completely changed the question I realized i do not have an infinite loop. I just assumed since I was running out of memory.

this line seems to be doing it and idk why..

P#65895 2019-07-16 23:07 ( Edited 2019-07-18 20:08)

What are you expecting it to do? (edit: genuine question, not intended as sarcasm) At the moment it looks like you're drawing your ship to the same position each frame, so it makes sense that the end result isn't changing. (your sprite rotation function doesn't seem to be used, though I didn't look too closely at the code, maybe I missed something)

P#65913 2019-07-18 00:31 ( Edited 2019-07-18 00:34)

Not sure if it will help you... I had an out of memory message when accidentally fell into recursion... have not fully got to the internals of your code but could be it given that crisscrossing of pointers to PROC() function...

P#66737 2019-08-17 19:01

In my opinion slainte is correct - your program has entered recursion.

At the line you have mentioned, procx is effectively an alias for proc, and you have called it on the object referred to by o.

o happens to be the object you are in, so it ultimately calls its own proc function, which it is already in, and it does this at the start of the proc function, so does it over and over and over ...

The alias is created when obj() attempts to put a reference to the parent's function into the object being created, but my understanding - from what's happening - is that this, when called as o.procx() will then be understood from the context of o. (I mean this description only as an observation of what's happening from the feedback I get from some printh comments I have put in.)

function obj(p,o)
 o=o or {}
    o.procx=p.proc or function(o2) end
    return setmetatable(o, {__index=p})

Here is your cart with a few small changes:

Cart #debugging_jajefutayu-0 | 2019-09-23 | Code ▽ | Embed ▽ | No License

If you start up pico-8 from the command line, this will now print out:

INFO: i am ship 1, countdown is 5
INFO: i am ship 1, countdown is 4
INFO: i am ship 1, countdown is 3
INFO: i am ship 1, countdown is 2
INFO: i am ship 1, countdown is 1
INFO: recursion detected, aborting ...

You'll also find the following in there:

-- o.p:proc(r-1)
-- o.p:procx(r-1)

Comment out the last line, and uncomment the first line. Running it again will then get you the following printh to the command line.

INFO: i am ship 1, countdown is 5
INFO: i am tobj

Besides which you'll be able to see and rotate your ship on screen.

I have used a "tostring" variable to give feedback. Delete these and the printh lines when you have no use for them.

I have created a p variable in tshp, to refer to the parent/prototype object referred to by the parameter tobj. I have presumed it was this object's proc (not procx) that you were trying to call at the start of proc.

I have presumed this was influenced by JavaScript and have just sent o to wrap() instead:

--      wrap(this,1,1)

I don't presume that the changes I have made are best or even good practice. I'm relatively new to pico-8 and Lua. While working through your code I looked at some information on OOP Lua (linked below), but the changes I have made are purely minimal changes to get the code to function; I have not attempted to discover if any code path should work without my changes in a fuller version of Lua, and I have not attempted to follow an established practice in the changes I have made.

Disclaimer: As such my code here is not meant to be something to work into anyone's OO Lua practice; if anyone wants better practices than these functional changes, please see instead the links below.

Two links for OO Lua:

lua.org, Programming in Lua: OOP chapter

lua-users wiki

P#68024 2019-09-23 10:52 ( Edited 2019-09-23 13:17)

thankyou guys for the help.
I will fix this as soon as I have time.

P#68191 2019-09-27 17:23

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-05-26 03:59 | 0.026s | 4194k | Q:46