Page 1 of 2
how to save the game score on close card
Posted: Fri Dec 21, 2012 8:56 am
by ahmedinvent24BUSGdU9
/Please Help\ how to save the score of a game on close card and stack! please help me
I developed a puzzle game that when the user complete the level he get a star now if he closed the game the star will be hidden.
so how to let the star saved when the user close the stack!
Please anyone help me, please!

Re: HOW TO SAVE THE GAME SCORE ON CLOSE CARD
Posted: Fri Dec 21, 2012 11:46 am
by Klaus
Hi Ahmed,
1. welcome to the forum!
2. please do open only ONE thread per question, and please in the correct forum, thanks!
I deleted the duplicate in "Announcements"(?).
3. Using CAPITALS only in headlines is considered as YELLING on the internet,
which is not polite and I'm sure you know that!
4. You can write to the users "Documents" folder, so you could do this.
a. Write data to a file:
Code: Select all
# on closestack or closecard:
...
put specialfolderpath("documents) & "/myprefs.txt" into myPrefsFile
put the_Variable_with_the_Highscore into url("file:" & myPrefsFile)
## Done writing to disk!
...
b. read that file back into your app:
Code: Select all
## on openstack or opencard or whenever you need it
...
put specialfolderpath("documents) & "/myprefs.txt" into myPrefsFile
put empty into mySavedPrefs
## Only read it if the file is present of course!
if there is a file myPrefsFile then
put url("file:" & myPrefsFile) into mySavedPrefs
end if
## Now mySavedPrefs contains NADA (probably the first start of your app) or the saved prefs data.
...
I recommend to check these stacks to get more of the basics of Livecode:
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Re: HOW TO SAVE THE GAME SCORE ON CLOSE CARD
Posted: Fri Dec 21, 2012 1:40 pm
by ahmedinvent24BUSGdU9
hi,
i'm really sorry for that , i really dont know that its not polite!
this my sample when i test it on android physical device the check sign hide on open card
please Klaus help me to fix that problem .
please download the file and fix the problem

Re: how to save the game score on close card
Posted: Fri Dec 21, 2012 3:18 pm
by Klaus
Hi Ahmed,
I already gave you some hints, I downloaded your stack but have no idea WHAT exactly you want to store in the preferences?
I will NOT fix your stack for you, but will help you to learn how to fix it yourself!
Do yourself a favour and check all the stacks in the URL I posted, you really need to get the basics of Livecode first!
Best
Klaus
Re: how to save the game score on close card
Posted: Fri Dec 21, 2012 6:47 pm
by ahmedinvent24BUSGdU9
thank you, Klaus
i will try.
Re: how to save the game score on close card
Posted: Fri Dec 21, 2012 6:51 pm
by Klaus
Hi Ahmed,
I will surely assist you, but as I wrote earlier:
...but I have no idea WHAT exactly you want to store in the preferences?
Best
Klaus
Re: how to save the game score on close card
Posted: Fri Dec 21, 2012 7:44 pm
by ahmedinvent24BUSGdU9
hi Klaus, i want to store a graphic or image.
please help
i'm 14 years old and new for developing please help me.
Re: how to save the game score on close card
Posted: Sat Dec 22, 2012 5:43 am
by dunbarx
Hi.
You are in good hands with Klaus.
But I do not understand where the idea came from, in the first reply, that data had to be read from, and written to, data files external to LC.
Klaus?
Now sometimes I miss the fact that mobile devices are the crux of many queries, even though this is never mentioned. So Ahmed, are you developing for mobile devices? Because if not, the solutions to your questions are far simpler. Write back if this is so.
Craig Newman
Re: how to save the game score on close card
Posted: Sat Dec 22, 2012 12:05 pm
by ahmedinvent24BUSGdU9
Hi, Craig
yes i am developing for mobile device.
please can you help me to do that?

Re: how to save the game score on close card
Posted: Sat Dec 22, 2012 12:58 pm
by Klaus
Hi Ahmed,
aha!
OK, "specialfolderpath("documents") also works on iOS and Android!
But I still do not know what you want!?
Here is what I found in your stack:
1. On the first card there is an image "level.png" and a graphic "fin1".
2. When I open the stack, the graphic "fin1" is not visible.
3. Clicking the image goes to card 2.
4. after I click "Play" on card 2, a little animation happens, I see a dialog and then
come back to card 1 and the graphics "fin1" is visible now.
What do you want to happen and when should that happen?
Please explain, I have really no idea until now
Best
Klaus
Re: how to save the game score on close card
Posted: Sat Dec 22, 2012 1:11 pm
by ahmedinvent24BUSGdU9
hi, Klaus
i need to know how when i close the app on the device and open it after a while the graphic still be visible such as the last time i closed the app.
but currently when i close the app the and open it after a while the graphic be hidden.
you can download this game that created by Eurotalk on iOS
http://www.facebook.com/l.php?u=https%3 ... =LAQFcKF2y
please help me!

Re: how to save the game score on close card
Posted: Sun Dec 23, 2012 5:13 pm
by ahmedinvent24BUSGdU9
Please anyone help me, please!

Re: how to save the game score on close card
Posted: Sun Dec 23, 2012 9:14 pm
by Simon
Hi Ahmed,
I think I see what you are trying to do. What you need we sometimes call a "preferences" file because not only can it be used to store things like the display language but other data. You can see one in action on that Euro Talk app as your name is saved up on top.
Now a preference or data file can be just a simple text file, for you as easy as this:
1
2
3
4
each number indicates a level passed and each time a level is passed you add a new number and save the file
Code: Select all
set the default folder to specialFolderPath("documents") --tell where to save the file
put tNewData & cr after tCurrentData -- add the new level
put tCurrentData into url "file:myData.txt" --save file
please look up "specialFolderPath" and "put" in the dictionary
With me so far?
Euro Talk has something like this:
Ahmed
1
2
3
4
Where they pull your name from line 1 of the data file and place it up on top of the display.
With the Euro Talk app your name shows up as soon as you open the app so the
data file must be read before the app actually is visible.
How?
Code: Select all
local tCurrentData -- the variable to save the data in
on preOpenCard
repeat with x = 1 to the number of graphics on this cd
hide graphic "fin" & x --hide all your check-marks *see note below
end repeat
set the default folder to specialFolderPath("documents") --as above we must set where to look for the file
put url "file:myData.txt" into tCurrentData --read the last data file saved
repeat for each line tLine in tCurrentData --read each line and see what is in it
set the visibility of graphic "fin" & tLine to true --- fin is your graphic, tLine will contain the numbers in the list and combine to make fin1, fin2, fin3 visible
end repeat
end preOpenCard
Please look up "preOpenCard", "local" and "global" in the dictionary.
* You mentioned that sometimes you see the check-mark and sometimes you don't this could be because you save the stack with the check-mark visible. If you are getting this on your Android mobile the difference is using the back button or home.
Think of the whole process as something "you" have to do to remember things.
Write yourself a note (put tNewData into note) and stick it in your pocket (specialFolderPath..)
to remember what is in the note
Take the note out of your pocket (specialFolderPath("pocket") and read it (put mynote into mybrain)
I given you a lot to think about but the basics are here. Your challenge is to make it work. No, you wont be able just to copy the above code and suddenly get the results you are looking for.
I will not look at your stack or help fix any check-mark related problems for you until you can show that you can write to a file, save it and then read it back into your stack to manipulate what is visible.
14 huh? You have made a good start with your "move" command,
Simon
EDIT: check-mark = tick-mark and preferences= data
Re: how to save the game score on close card
Posted: Mon Dec 24, 2012 12:28 pm
by ahmedinvent24BUSGdU9
thank you Simon for your help

i understood some of what you said but still doesn't work
i will try that idea its really amazing.
thank you!
Re: how to save the game score on close card
Posted: Mon Dec 24, 2012 8:18 pm
by Simon
i understood some of what you said but still doesn't work
It won't work until you've understood
all that I've said.
Simon