Strange issue with objects/ properties

So all my work got deleted when my iPad set a pass code on itself which is the darnedest thing…had to restore my iPad and 2000 lines of a project I was working on the last 3 days was deleted…no matter because everything that you did once you can do it better…especially programming and writing in General…but the lesson is to backup often aha…

Anyway, in recreating my program I have a class-object hierarchy as follows…

Hands are part of the Hero (played)
The Hero is part of the Story (mode)
The Story is part of the Main program…

Example: mode.player.hand.x returns the x value of a hand…

Anyway, the Hero also has a body, which is just a physics circle and doesn’t really need it’s own class.

And this hierarchy was working fine yesterday in my old project buuuuuut…

When I’m in the init function of one of my hands (there’s 2), I have this…

function Hand:init(x, y)
    -- you can accept and set parameters here
    self.ball = physics.body(CIRCLE, 5 * .75)
    self.ball.gravityScale = 0
    self.ball.x = x
    self.ball.y = y
    
-- print(mode.player.ball.radius)
end

The above debug print statement when uncommented returns the following error: "attempt to index global ‘mode’ (a nil value)
And in the “self.ball = physics.body(CIRCLE, 5 * .75)” section of my init function, I’d like to replace the 5 with the content in the debugging print line…

However, when I call that very same print statement in the draw function of the Hand object, it returns 15, which is the correct value of there player-ball-radius…

See below…

function Hand:draw()
    -- Codea does not automatically call this method
  --  ellipse(self.x, self.y, self.ball.radius * 2)
  --  print(mode.player.ball.radius)
end

Help? I don’t want to bandaid this…I’d rather fix it and code it correctly…thoughts?

And do you need the other classes in my code to debug? Let me know :slight_smile:
Thanks!!

Is player:init called in mode:init? If so this may be because mode hasn’t been defined yet. Player:init needs to finish and then return to mode:init which will finish and.get to the line: mode=story() and then mode will be defined. (I may be wrong about this though)

Yeah I just figured that out literally 5 seconds after I wrote this all out aha ;)…silly silly…my solution to this is to change the Hand:init(x,y) to

Hand:init(x,y,ballRadius)

Where ballRadius is the player.ball.radius when it’s passed.

Thanks :slight_smile: