What you gave me to add for main.lua is in Ice2.lua, menu.lua is in Ice3.lua. I've been changing some of it but every time I tap on "Press" in Ice2.lua it says failed to execute new (params) function on 'Ice3'. I guess something is wrong in Ice3.lua, I gave you exactly what I have below.
Hi Michael, you need to put some of the key elements back to main.lua -- if you absolutely want/need to keep them outside of main.lua, I am unable to help further. I'd say, in that case, you'd be better off seeking help from Graham (who created this library). Anyhow, see below how I would modify your code. (Not tested but it should work.)
Naomi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| -- main.lua
require("ice")
myData = nil
-- load previously saved data
-- EDIT: if no data has been saved, it will create the myData.ice where data will be saved
myData = ice:loadBox( "myData" )
--Ice.lua :
module(..., package.seeall)
function new()
local iceGroup = display.newGroup();
-- try and retrieve the fixed score
local setScore = myData:retrieve( "mySetScore" )
if (setScore == nil) then
setScore = 12345 -- this is the fixed score you want to use
myData:store( "mySetScore", setScore )
end
myData:save() -- this will save the data to device
Press = display.newText( "Press", 0, 0, "Helvetica", 30 )
Press.x = 100
Press.y = 100
iceGroup:insert(Press);
function ther4(event)
director:changeScene( "Ice2", "fade" )
end
Press:addEventListener("tap", ther4);
return iceGroup;
end
--Ice2.lua:
module(..., package.seeall)
function new()
local ice2Group = display.newGroup();
local setScore = myData:retrieve( "mySetScore" )
print("setScore = " .. setScore) -- this should print "12345" to terminal
return ice2Group;
end |
I LOVE YOU! Thanks so much Naomi! It worked!
One more question. So when I change "setScore" numbers and reload the simulator it stays the same number. I saw something about clearing the data, do you know what I could do to do that? So what i mean is that instead of 12345 for setScore i put 54321 and it stayed 12345. So I was wondering what I could do to clear it every time so the score can change.
THANKS AGAIN. YOUR AWESOME.
Also one thing that i noticed is that when I erased "myData:save()" Ice.lua it does not change anything. I'm trying to use "myData:clear()", I'm adding it in difference positions but it doesn't seem to do anything.
Hi Michael, I'm glad I could help.
About myData:save() function, you need to store the data first and then use the save function while in the same module.
So, if you are in Ice1.lua file, and if you store some data, you need to call save function before you leave Ice1.lua to ensure the data is saved to myData -- storing data in Ice1.lua and moving on to Ice2.lua and then calling the save function won't save the data stored while in Ice1.lua.
About myData:clear() function, it will clear out all data from myData. Try using myData:clear() function and check the myData.ice file in the sandbox. You'll see all stored data are gone.
So... don't use clear function unless you really want to wipe clean. Instead, when you want to change the value of stored/saved data, use store function to store a value and then call save function before leaving the module.
Naomi
I'm not sure you know what I mean. What I meant was that when you tap on Press and it displays 12345, in the sand box the number is stored. So when I change the number to let's say 54321 the number does not change unless I erase the data in the sandbox. So I was wondering If i could erase the data in the sandbox using some code so every time the score can update it self. Let's say i have a game and the score is constantly changing, i need the sandbox to erase itself so that i can add the new score. Because at the moment it is just storing the number 12345 and I can't change the number, because it is stored in the sandbox. Do you know what I can do to fix this? That is why i brought of the myData:clear(), but it does not work so what can I do?
Besides the point I recently have made a timer counting up, but the score is not the number the counter is at once I tap on Press and go to the Ice2.lua, it is the number the score starts at which is 0. What I did is make a make a counter timer, i set it at 0 increasing by one each second. The problem is that when I tap on Press and go to Ice.lua it does not show the current number, it shows 0. I want it to show the current number it is once I tap on Press. Do you know what I mean? Let's say the timer has gone up to 8 and I tap on press, the score that it shows me is O, the starting number not the current number.
What I did differently was I made the timer, and once you tap on press it brings you to ice2.lua. On Ice2.lua it is suppose to display the current score, but it shows 0. I added text so now it is not using terminal.
Thanks a lot for your help, I really appreciate it. I'm sorry for all this, i'm really a newbie.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| -- main.lua
require("ice")
myData = nil
-- load previously saved data
-- EDIT: if no data has been saved, it will create the myData.ice where data will be saved
myData = ice:loadBox( "myData" )
--Ice.lua :
module(..., package.seeall)
function new()
local iceGroup = display.newGroup();
-- try and retrieve the fixed score
local setScore = myData:retrieve( "mySetScore" )
if (setScore == nil) then
setScore = 0-- this is the fixed score you want to use
myData:store( "mySetScore", setScore )
end
myData:save() -- this will save the data to device
local scoreText = display.newText( "Score: " .. setScore, 20, 0,nil, 20)
scoreText:setTextColor(255,255,255)
local function getScore() -- increments score value every time it is called
setScore = setScore + 1
scoreText.text = "Score: " .. setScore
end
timer.performWithDelay(1000, getScore, 0)
Press = display.newText( "Press", 0, 0, "Helvetica", 30 )
Press.x = 100
Press.y = 100
iceGroup:insert(Press);
function ther4(event)
director:changeScene( "Ice2", "fade" )
end
Press:addEventListener("tap", ther4);
return iceGroup;
end
Ice2.lua:
--Ice2.lua:
module(..., package.seeall)
function new()
local ice2Group = display.newGroup();
local setScore = myData:retrieve( "mySetScore" )
local scoreText = display.newText( "Score: " .. setScore, 20, 0,nil, 20)
scoreText:setTextColor(255,255,255)
return ice2Group;
end |
views:1810 update:2011/12/30 9:10:41