Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
2 - Arcoverde

My program stops suddenly

Question

MinecraftOC.thumb.png.e9715c7be14132fc71c15049ddac3682.png

I have this program, I am trying to use a pairing function(https://en.wikipedia.org/wiki/Pairing_function) so I can have a unique number attached to a x,y,z triplet <<x,y>z>, tried doing it via table[x][y][z] not enough memory

But for some reason after x=17 it stops, not the loop stops, the whole program shutdown as it had finished, but it should have printed "works" at the end

No error given

I would really appreciate any help

Ps: I tested it on Lua IDE on windows, it works. I have no idea whats happening

pairing.lua

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

It works on Creatix! Takes a loong time to get there, but it makes it.

Perhaps if you hop into a creative world and experiment with different builds of robot until you can isolate what component is causing the problem?

itworks.png

Share this post


Link to post
Share on other sites
  • 0

Usually, if your code stops abruptly and prints no error (and you're not running it in a thread or an event listener), it's safe to assume you've run out of memory or got a "too long without yielding" error. I'm guessing it's the former. Your loop adds 65536 elements to a table. That's a lot. Lua numbers are 8 bytes long, so you'll need at least 512 kiB of memory. Actually, since you're using a table, it requires more than 1 MiB of RAM. That's the lower bound, and I haven't even considered the fact that you create 65536 more tables, one for each call to the Pairing function, so you should expect it to need even more memory.

But first check if the error got written to /etc/event.log. It's the usual place for many hidden errors to go.

Share this post


Link to post
Share on other sites
  • 0

Thank you for the help, but I resolved it.

You are right, these are too many values, I resolved it by making it a single string that I concatenate over and over, generating a very big string but way easier in memory

I can retrieve the exact number as long as I know what is the biggest and the smallest number on x,y,z

Code say better than words

For x=-a,a do

 For y=-b,b do

  For z=-c,c do

...

  End

 End 

End

Assuming concatenate results, to retrieve it:

Place=(x*b*c+y*c+z)*NumberDigits

Counter=0

For digit in string.gmatch(value, "%d") do

 If place==counter than 

  ...

 Else

 Counter=counter+NumberDigits

 End

End

If someone else has a similar problem, I hope this solution can help

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.