Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

After tap play button load level with function ?
Started by presentxy Jul 29 2018 12:32 AM

4 replies to this topic

Best Answer Rob Miracle , 29 July 2018 - 04:54 PM

That's actually a different error.

 

Notice this is an error is now staying that stage1 is a nil value on a different line number. Now, your program is failing to load Stage1.png. I suspect the reason is you're using a Window's syntax for the file names with back-slashes. Generally, in Corona, file names and paths follow the Unix format using forward slashes. Try using:

 

"Images and Icons/Stages/Stage1.png"

 

There are a few other things to think about. While the Windows and macOS file systems are generally not case sensitive, Android and iOS are. So later on, when building for mobile devices, if the filename is really "stage1.png", it will work on the simulator on Windows, but on an Android device, it will give you an error.

 

Spaces in path names and file names "should be" safe, but in my experience, it's not. Many times a path will a parameter to a script that gets run in the background and spaces have special meaning when running command line scripts and if they are not escaped properly, hard to diagnose problems could occur. Of course, you're not running these scripts and it would be a bug that would need to be fixed, but, it's easy to avoid having the problem in the first place by not having spaces in your file and path names. It's just a good practice.

 

Finally, it's a best Forum practice to learn how to share code. Doing it through screen captures isn't the best way to get help. You can use copy and paste, to copy the code from your text editor and paste it into your forum post. If you do, click on the blue <> button and paste your code in. 

 

Then for your error messages, you can use the Corona console log and copy the error from that window and paste it into your forum post. This will save you having to annotate an image, its quicker and for people helping you if we want to correct something in your code, we can copy and paste from the message, something we can't do from an image.

 

Rob

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

presentxy

[GLOBAL: userInfoPane.html]
presentxy
  • Observer

  • 5 posts
  • Corona SDK

I tried to do when i press the startbutton1 it is actually play button after that immediately load new level and start playing games. but corona gives error ,attempt to call global index a nil value stack traceback?

 

 

Attached Files



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,331 posts
  • Corona Staff

Lua, the language Corona uses is a single-pass compiler. This means every variable and function has to be defined before you use it. When the compiler scans your code and see ST1() on line 26, it doesn't exist, therefore it's nil. Lua doesn't know what ST1 is yet until it compiles line 44 which is too late.

 

The solution is to move the function ST1 higher up in your code before the handleEventButton function.

 

Rob



[TOPIC: post.html]
#3

presentxy

[GLOBAL: userInfoPane.html]
presentxy
  • Observer

  • 5 posts
  • Corona SDK

Lua, the language Corona uses is a single-pass compiler. This means every variable and function has to be defined before you use it. When the compiler scans your code and see ST1() on line 26, it doesn't exist, therefore it's nil. Lua doesn't know what ST1 is yet until it compiles line 44 which is too late.

 

The solution is to move the function ST1 higher up in your code before the handleEventButton function.

 

Rob

 

thanks for answer but same error...



[TOPIC: post.html]
#4

presentxy

[GLOBAL: userInfoPane.html]
presentxy
  • Observer

  • 5 posts
  • Corona SDK

MY ERROR :

 

https://image.ibb.co/dvRcZT/2.png



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,331 posts
  • Corona Staff

  Best Answer

That's actually a different error.

 

Notice this is an error is now staying that stage1 is a nil value on a different line number. Now, your program is failing to load Stage1.png. I suspect the reason is you're using a Window's syntax for the file names with back-slashes. Generally, in Corona, file names and paths follow the Unix format using forward slashes. Try using:

 

"Images and Icons/Stages/Stage1.png"

 

There are a few other things to think about. While the Windows and macOS file systems are generally not case sensitive, Android and iOS are. So later on, when building for mobile devices, if the filename is really "stage1.png", it will work on the simulator on Windows, but on an Android device, it will give you an error.

 

Spaces in path names and file names "should be" safe, but in my experience, it's not. Many times a path will a parameter to a script that gets run in the background and spaces have special meaning when running command line scripts and if they are not escaped properly, hard to diagnose problems could occur. Of course, you're not running these scripts and it would be a bug that would need to be fixed, but, it's easy to avoid having the problem in the first place by not having spaces in your file and path names. It's just a good practice.

 

Finally, it's a best Forum practice to learn how to share code. Doing it through screen captures isn't the best way to get help. You can use copy and paste, to copy the code from your text editor and paste it into your forum post. If you do, click on the blue <> button and paste your code in. 

 

Then for your error messages, you can use the Corona console log and copy the error from that window and paste it into your forum post. This will save you having to annotate an image, its quicker and for people helping you if we want to correct something in your code, we can copy and paste from the message, something we can't do from an image.

 

Rob


  • presentxy likes this


[topic_controls]
[/topic_controls]