Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

NewTextFile behavoir simulator vs device
Started by nacho.gbm91 Dec 09 2019 06:30 AM

1 reply to this topic
newtextfile
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

nacho.gbm91

[GLOBAL: userInfoPane.html]
nacho.gbm91
  • Observer

  • 2 posts
  • Corona SDK

Hi,

 

I have developed my first game in corona simulator. I am wondering why the newtextfile object has different behavoir during the simulation than during device execution.

 

The code has a newtextfile to indicate the number of players. I want this box to have a default value, so:

 

NumPlayersField = native.newTextField(display.contentCenterX+100, display.contentCenterY+10, 35, 35 )
NumPlayersField.inputType = "number" 
--Default value
NumPlayersField.text = "4"


NumPlayers=tonumber(NumPlayersField.text)
composer.setVariable("NumPlayers",NumPlayers)
 
NumPlayers is the local varible that store this default value ("4") and the next scene reads this value:
 
NumPlayers=composer.getVariable("NumPlayers")
 
During the simulation, the value of this variable is filled with this default value but not during the execution in the device. The game crashes because the next scene has a for loop that depends on this value NumPlayers and this variable is empty. 
 
NOTE: I have also tried this with NumPlayers as global variable instead of local. 


[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 711 posts
  • Corona SDK

Hi Nacho, 

 

Please use the "<>" buttons in the tool bar to format your code.  Many people won't spend time looking at it if it is not formatted.




[topic_controls]
[/topic_controls]