wtf with my regeneration

Hi I took a quick look at the contents of the RAR, but I can’t make heads or tails of it.  There is NO indentation at all, everything is aligned left.  Is this on purpose?  Whatever the case, it makes the code way too hard to read.

Also, I noticed that you’ve got a function,

function gengame(num\_lvl) ... end

and in this function you create a bunch of other (global) functions.  This just isn’t going to work.  I mean it could work but it would be so prone to error that I’d suggest again doing this:

  1. Start over.

  2. Write individual functions, no functions in functions.

  3. Use forward declaration (as shown above) to provide access to functions that need to be called in other functions.

  4. Reduce as much as possible.  

I think if you do this, the problem will either go away or be much easier to find.

That’s the best I can do for you.

Rob, I have attached a zip file to the old post

roaminggamer

Objects that are used in functions are local and Lua complains when the functions are global, all the more so in the function gen () I initialize function, and then delete it

and code with tabs

Guys… i need in yours help

I can’t afford the time to help.  I’ve looked at your latest download and it still has the same issues I’ve asked you to address:

  • Creates global functions inside other functions for no discernible reason
  • multiple blank lines for no reason
  • erratic indentation

I have to make a living and digging through this will take at least an hour to work out what is intended and what is happening. 

I want to help you, but I want to pay my mortgage more.  Sorry boss.

Note: Above you said something about locals and globals I didn’t understand, but I think you’re misunderstanding the concept.

Please see below:

-- The wrong way to write code and these are all global functions -- function a() function b() print("b") end b() end function c() a() end c() -- creates b() and prints "b" c() -- creates b() AGAIN (wipes out old one) b() -- prints "b"; function was created in call to c() --\> call to a() 

-- The right way to write code/functions when you need to call them from each other -- -- Forward declarations local a local b local c -- Definitions a = function() b() end b = function () print("b") end c = function() a() end c() c() b()

I think what’s important to remember, as well, is that this isn’t a problem that is impossible to solve. It’s not like you’ve stumbled upon some brand new concept in the “mobile game physics body regeneration” space. What you are attempting to accomplish is possible, but not in the way you attempting to accomplish it currently.

Your best bet is to stop development on your current project, create a new project that JUST focuses on the problem you are encountering here. Work on that until you feel you can solve the concept and get it working reliably for that small mini-project. Then you can put the logic you created in the mini-project, into your larger project.

I realize this might seem pointless, but I guarantee that it will help you figure out the problem, and help you to understand the best way to debug other problems that will inevitably arise as well. 

Good luck!

Alex@Panc

You have not read my previous posts …

Everything works … but when i reloading all variables ,then they are  switched off in many areas of physics … all … but i localized this problems, but in the cycle this problems is not solved …

roaminggamer

I will try to edit the code as you advised…

However, Lua … … me a little alien with a = function () … it’s like in js … but I avoid such constructions, because i don’t like their…

Yeah, you don’t have to do it the way I showed.  If you have a function A that is called by B simply declare A before B and you’re fine too:

local function a() print("a") end local function b() a() end

I showed you how to use ‘forward declaration’ because that helps solve sticky issues where resolving scope by declaration order is not feasible.

If Lua is foreign to you, I’d strongly suggest learning more about it before jumping into developing a game.

Simply take some online tutorials or buy a book that teaches Lua and use Corona to learn in.

You can put anything in main.lua, so simply writing Lua programs in main.lua and learning Lua first is completely doable.

Once you understand Lua, you’ll have a much better foundation for playing with Corona features.

Lua and JavaScript are not that drastically different.  In JS you use { and } to mark the beginning and ending of blocks.  You would write:

function myFunction( someparamters ) {

      // do stuff

}

in Lua thats

function myFunction( some paramters )

     – do stuff

end

They are very similar.  In Javascript you indent each block of code so you can match your closing braces } with the block that started it (function, if, for, etc.).  In Lua you do the same with “end” instead of }

I looked at your code.  It’s really, really hard to read.  Between the indenting problem where we can’t tell where one function begins or ends and the functions within functions I can’t really help.

What part of your code is resetting the game?  What function is doing this work?

Rob

@gleb269,

I’m dying to see this resolved, but you’ll have to help us help you.  The primary issue is that your code is not legible.  If I could simply read the code without struggling I’d probably be able to help.

Let me show you what I mean.  

This is well formatted code:

local function quad( a, b, c ) local sol if( math.abs( a ) \< tiny ) then if( math.abs( b ) \< tiny ) then if( math.abs( c ) \< tiny ) then sol = { x = 0, y = 0 } else sol = nil end else sol = { x = -c / b, y = -c / b } end else local disc = b \* b - 4 \* a \* c if (disc \>= 0) then disc = math.sqrt( disc ) a = 2 \* a sol = { x = ( -b - disc ) / a, y = ( -b + disc ) / a } end end return sol end 

This example of what your code is like:

local function quad( a, b, c ) local sol if (math.abs(a) \< tiny) then if (math.abs(b) \< tiny) then if (math.abs(c) \< tiny) then sol = {x=0, y=0} else sol = nil end else sol = {x=-c/b, y=-c/b} end else local disc = b\*b - 4\*a\*c if (disc \>= 0) then disc = math.sqrt(disc) a = 2\*a sol = { x=(-b-disc)/a, y=(-b+disc)/a } end end return sol end 

To be clear:  I’m not showing you this to make fun of you or shame you.  I just want you to see the difference and to help you understand our plight.  

If you look at both samples above, you’ll notice something.  Although you probably don’t know what the function does right away, you at least have the possibility of figuring it out by looking at the formatted one.  The un-formatted one is impenetrable, even though it is the same code.

So, please take some time to indent your code and to get rid of unnecessary blank lines.

The repost the link.  Then we’ll have a chance of resolving this.

Thanks,

Ed