Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Call method scale nil value, help!
Started by dodi_games Mar 23 2019 04:28 PM

2 replies to this topic
scale error

Best Answer nick_sherman , 23 March 2019 - 05:45 PM

You need to set up a flag that says whether or not it is safe to exit the scene.

At the moment the user can press either button multiple times, each firing off the process to scale and leave the scene. If both are pressed, after 200 ms the scene is destroyed, and then after 300ms it tries to scale a button that no longer exists.

Check that is true, and then set to false, whenever either button is pressed.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 370 posts
  • Corona SDK

Hi guys! This time I have encountered a problem that I do not know how to solve. In my game, each level has a home button which has an animation that enlarges the image. This animation was carried out using the function "object: scale ()" to increase the image and with a short timer to shrink the image, which gives the visual aspect of enlarge and shrink to enter the other scene. Everything works fine, but one of my testers, who is a natural born gamer, found that if you press the home button and the Android back button at the same time, a crash occurs. Here is the home button function:

local function gotoMenu( event )
  home:scale( 1.3, 1.3 )
  local options = { effect = "crossFade", time = 200 }
  homeBtnTmr = timer.performWithDelay(300,
    function()
      home:scale( .80, .80 )
      composer.gotoScene( "levels.menu", options )
    end
  )
  return true
end

The back button function is configured in main, I assign a variable to the composer in each level but the function is executed from the main lua. It is an old method that I found navigating the forum and the internet and I had not given problems until now. Here is the piece of code that executes the return to the menu from the back button.

local function onKeyEvent( event )
   local phase = event.phase
   local keyName = event.keyName
   print( event.phase, event.keyName )
   if keyName == "back" and phase == "up" then
     if composer.getSceneName( "current" ) == "levels.menu" then
       native.requestExit()
       return true
     else
       local lastScene = composer.returnTo
       print( "previous scene", lastScene )
       if lastScene then
         local options = { effect = "crossFade", time = 200 }
         composer.gotoScene( lastScene, options )
         return true
       else
         native.requestExit()
       end
     end
   end
   return false
end

any help to understand and solve why this error "level"#".lua:134: attempt to call method 'scale' (a nil value)" comes out I'll be very greatful!

 

Thanks in advance

DoDi

 



[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,787 posts
  • Corona SDK

  Best Answer

You need to set up a flag that says whether or not it is safe to exit the scene.

At the moment the user can press either button multiple times, each firing off the process to scale and leave the scene. If both are pressed, after 200 ms the scene is destroyed, and then after 300ms it tries to scale a button that no longer exists.

Check that is true, and then set to false, whenever either button is pressed.
  • dodi_games likes this

[TOPIC: post.html]
#3

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 370 posts
  • Corona SDK

Thanks @nick_sherman you opened my mind!




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: scale, error