[edit] i put these functions in the update function ,will got a nil result but in the init function ,it output a right value.
the problem is , i am trying to create a game object out of screen ,then it moves in. so I have to get screen height or width value first in the render script, but in the init function ,the render is not run yet? so i cannot get the screen value
function update(self, dt)
-- Add update code here
-- Remove this function if not needed
self.role_pos = role_position
self.random_top = math.random(screenW+50,screenW+150)
print(random_top)
self.pos = vmath.vector3(random_top,screenH+50,0)
self.to_role_angle = math.deg(math.atan2(self.role_pos.y - self.pos.y, self.role_pos.x - self.pos.x))
print(to_role_angle)
end
to sergey.lerg
I also tried your ways,but not works ,too
The first line sets the variable “self.random_top” to a value.
The second prints a variable called “random_top”, which is a different variable. Since it has not been initiated yet it’s nil. Change this to print(self.random_top).