Jump to content




Lua Program Pulling a java error!

java lua

8 replies to this topic

#1 jadelade

  • Members
  • 43 posts

Posted 06 July 2013 - 12:05 AM

My program (iz9SESzF[setup to pull the error after starting it and pressing "Q". sorry for the messy/ugly program]) is chucking a java error at me (java.lang.ArrayIndexOutOfBoundsException) and i need a little help punching it out... IF I CAN!

#2 M4sh3dP0t4t03

  • Members
  • 255 posts
  • LocationGermany

Posted 06 July 2013 - 12:59 AM

java.lang.ArrayIndexOutOfBoundException is happening when a function is called more than 256 times at once. This probably is because the play function is calling itself at line 345(I'm not sure if that's the problem, but i'ts the only thing I saw after looking over the code quickly that could cause this).

#3 jadelade

  • Members
  • 43 posts

Posted 06 July 2013 - 01:44 AM

Thats what i was thinking i dont know much about java. can you suggest a better way of repeating the function?

#4 xbsktball10x

  • Members
  • 26 posts

Posted 06 July 2013 - 02:01 AM

while true do
function()
end

this is of course assuming you have a yield in your function otherwise it will throw the "running to long without yielding" exception

#5 jadelade

  • Members
  • 43 posts

Posted 06 July 2013 - 02:12 AM

i will need to use more logic than just that.

#6 xbsktball10x

  • Members
  • 26 posts

Posted 06 July 2013 - 02:14 AM

I cant find anywhere in the code that would be throwing this. I happens to me if i call a call a function inside of its own function. i did just look it over quickly but maybe look for a function calling itself. The only thing i can see there being a problem would be calling draw() alot inside of all the other functions

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 06 July 2013 - 02:31 AM

View Postjadelade, on 06 July 2013 - 01:44 AM, said:

Thats what i was thinking i dont know much about java. can you suggest a better way of repeating the function?
The problem has nothing to do with you programming anything for Java. The only reason it shows a Java error is because the problem occurs in the Java implementation of Lua (LuaJ), where the stack object used to store the function call stack overflows and throws and exception. Read what I say in the next quote to find an answer of 2 fixes, one which is highly recommended and the other is a temporary solution before doing the first fix.

View Postxbsktball10x, on 06 July 2013 - 02:01 AM, said:

while true do
function()
end
this is of course assuming you have a yield in your function otherwise it will throw the "running to long without yielding" exception
Not quite, the only way that it can be fixed is with a restructure of the code which I highly recommend to the OP short of that tail calls could be used to stop the recursive loop.
return play( value )
but I still say you should restructure the code so that it follows a better design pattern so that there is no need for recursion or tail calls!


View Postxbsktball10x, on 06 July 2013 - 02:14 AM, said:

can you please post the code
OP has the code in there

Quote

iz9SESzF

Edited by theoriginalbit, 06 July 2013 - 02:34 AM.


#8 jadelade

  • Members
  • 43 posts

Posted 06 July 2013 - 04:59 AM

View Posttheoriginalbit, on 06 July 2013 - 02:31 AM, said:

View Postjadelade, on 06 July 2013 - 01:44 AM, said:

Thats what i was thinking i dont know much about java. can you suggest a better way of repeating the function?
The problem has nothing to do with you programming anything for Java. The only reason it shows a Java error is because the problem occurs in the Java implementation of Lua (LuaJ), where the stack object used to store the function call stack overflows and throws and exception. Read what I say in the next quote to find an answer of 2 fixes, one which is highly recommended and the other is a temporary solution before doing the first fix.

View Postxbsktball10x, on 06 July 2013 - 02:01 AM, said:

while true do
function()
end
this is of course assuming you have a yield in your function otherwise it will throw the "running to long without yielding" exception
Not quite, the only way that it can be fixed is with a restructure of the code which I highly recommend to the OP short of that tail calls could be used to stop the recursive loop.
return play( value )
but I still say you should restructure the code so that it follows a better design pattern so that there is no need for recursion or tail calls!

I was thinking of having a while loop to repeat the line of code if it repeat the same table in the programs table. Would this improve(not fully fix it) the problem?

#9 jadelade

  • Members
  • 43 posts

Posted 07 July 2013 - 12:07 AM

nevermind i just started returning the play()





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users