It looks like you're new here. If you want to get involved, click one of these buttons!
Hello.
I am new here and i have created al little test game for my own, but it doesn’t works.
I would like to save the variable „p“ (total points), but it doesn’t works..
I know that it is this command „saveLocalData=("save_p"), p“... but i can’t put it on the right place...
Can you help me please?
-----------------------------------------
-- Coin Kollektor
-- Written by Biberjumper
-----------------------------------------
-- Description
-- You can touch and you get points
-- you can save this points, by standing on the chest, and clicking "x" or "X"
-- The points at the top will be saved, but the points at the Button, will be deletet, wen you dont click x by the Box
--
-- You can move with "w, a, s, d"
-- I hope you have Fun
-- P.s. Sorry for my Englisch... I am a german boy... xD
-----------------------------------------
-- Coin Kollektor
displayMode(FULLSCREEN)
function setup()
print("Gehe auf die Kiste und Sammle die Klick punkte mit x")
showKeyboard()
--Spieler und Kiste werden erstellt
player=sprite("Planet Cute:Character Boy")
chest=sprite("Planet Cute:Chest Closed")
--x und p werden erstellt und gespeichert
fontSize(200)
fill(0, 200, 255, 255)
x=readLocalData("save_x") or 0
p=readLocalData("save_p") or 0
t=readLocalData("save_t") or 0
--Bewegungen
px=100
py=HEIGHT-100
--Kiste
chestClosed=true
--Schalter
parameter.boolean("HACKING")
--Uhr
t = 0
--Spielzeit wird beim Drücken angezeigt
parameter.action("Wie lange spiele ich schon?", function() print("Time: "..math.ceil(t)) end)
--ClearOutput
parameter.action("Clear Output", function() output.clear() print("Sucsess!") end )
end
function draw()
--Hintergrund wird gezeichnet
sprite("SpaceCute:Background",512,384,1024,768)
--Punkte werden hir angezeigt
text(math.tointeger(x),500, 150)
text(math.tointeger(p),500, 600)
--Kiste und spieler werden Gemalt
if chestClosed then chest=sprite("Planet Cute:Chest Closed", WIDTH/2, HEIGHT/2) end
player=sprite("Planet Cute:Character Boy", px, py)
showKeyboard()
--Schalter einstellungen
if HACKING == false then
else
x=x+1
end
--Clock
t = t + DeltaTime
--Zeit wird gespeichert (funktioniert noch nicht...)
saveLocalData=("save_t"), t
end
function touched(touch)
--Berührungen werden wahrgenommen
if touch.state==BEGAN then
x=x+1
end
end
function keyboard(key)
--Tastatur reagiert auf Tasten
if (key == "w" or key == "W") then
py = py + 40
end
if (key == "a" or key == "A") then
px = px - 40
end
if (key == "s" or key == "S") then
py = py - 40
end
if (key == "d" or key == "D") then
px = px + 40
end
if (key == "x" or key == "X") then
if touchingChest() then
chestClosed=true
sound(SOUND_PICKUP, 24870)
p=p+x
x=x-x
end
end
end
--Position der Kiste wird angegeben
function touchingChest()
if (px < WIDTH/2+50 and
px > WIDTH/2-50 and
py < HEIGHT/2+85 and
py > HEIGHT/2-85) then return true
else
return false
end
end
Comments
Sorry for the Code window... I don’t can fix it...
@Biberjumper Whenever you post code, put ~~~ on a line before and after your code. The command to save local data is
saveLocalDate(“save_p”,p)
. That can be put afterp=p+x
in the keyboard function. The reason you’re having trouble with it is because at the end of the draw function you have the codesaveLocalData=(“save_t”),t
which is redefiningsaveLocalData
to something else. That should be removed. Also, you might not want to put it in the draw function because the draw function gets executed 60 times per second. Maybe you can putsaveLocalData(“save_t”,t)
in the touched() function to save it anytime the screen is touched.It doesn’t works again...
@Biberjumper The reason it doesn’t work is because in line 70 in the image above, you’re redefining what saveLocalData is. Remove the line
saveLocalData=
and try again. When you redefine a function, then it doesn’t do what it’s intended to do which is why it’s giving you an error.Do you mean it like this?
@Biberjumper I meant for you to remove the whole line. Get rid of the
(“save_t”),t
. The format for save local data issaveLocalData(“keyname”,value)
.Do you mean it like this?
Sorry... I am to dump...
Aaaah Ok... Thank you! I understand