how to save the game score on close card

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

ahmedinvent24BUSGdU9
Posts: 43
Joined: Mon Oct 15, 2012 6:44 pm

how to save the game score on close card

Post by ahmedinvent24BUSGdU9 » Fri Dec 21, 2012 8:56 am

/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! :(
Last edited by ahmedinvent24BUSGdU9 on Sun Dec 23, 2012 5:13 pm, edited 2 times in total.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: HOW TO SAVE THE GAME SCORE ON CLOSE CARD

Post by Klaus » Fri Dec 21, 2012 11:46 am

Hi Ahmed,

1. welcome to the forum! :D

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

ahmedinvent24BUSGdU9
Posts: 43
Joined: Mon Oct 15, 2012 6:44 pm

Re: HOW TO SAVE THE GAME SCORE ON CLOSE CARD

Post by ahmedinvent24BUSGdU9 » Fri Dec 21, 2012 1:40 pm

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 :)
Attachments
puzzle sample.zip
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
(1.8 KiB) Downloaded 321 times

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how to save the game score on close card

Post by Klaus » Fri Dec 21, 2012 3:18 pm

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

ahmedinvent24BUSGdU9
Posts: 43
Joined: Mon Oct 15, 2012 6:44 pm

Re: how to save the game score on close card

Post by ahmedinvent24BUSGdU9 » Fri Dec 21, 2012 6:47 pm

thank you, Klaus
i will try.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how to save the game score on close card

Post by Klaus » Fri Dec 21, 2012 6:51 pm

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?
:D


Best

Klaus

ahmedinvent24BUSGdU9
Posts: 43
Joined: Mon Oct 15, 2012 6:44 pm

Re: how to save the game score on close card

Post by ahmedinvent24BUSGdU9 » Fri Dec 21, 2012 7:44 pm

hi Klaus, i want to store a graphic or image.
please help :cry:

i'm 14 years old and new for developing please help me.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: how to save the game score on close card

Post by dunbarx » Sat Dec 22, 2012 5:43 am

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

ahmedinvent24BUSGdU9
Posts: 43
Joined: Mon Oct 15, 2012 6:44 pm

Re: how to save the game score on close card

Post by ahmedinvent24BUSGdU9 » Sat Dec 22, 2012 12:05 pm

Hi, Craig

yes i am developing for mobile device.

please can you help me to do that? :cry:

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how to save the game score on close card

Post by Klaus » Sat Dec 22, 2012 12:58 pm

Hi Ahmed,

aha! :D

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 8)


Best

Klaus

ahmedinvent24BUSGdU9
Posts: 43
Joined: Mon Oct 15, 2012 6:44 pm

Re: how to save the game score on close card

Post by ahmedinvent24BUSGdU9 » Sat Dec 22, 2012 1:11 pm

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! :(
Attachments
IMG_1234.zip
This is an image for that game now i get stars when i close the app then open it after a while the stars still visible, so how to make the stars still visible such as this game?! please help :(
(229.16 KiB) Downloaded 302 times

ahmedinvent24BUSGdU9
Posts: 43
Joined: Mon Oct 15, 2012 6:44 pm

Re: how to save the game score on close card

Post by ahmedinvent24BUSGdU9 » Sun Dec 23, 2012 5:13 pm

Please anyone help me, please! :(

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: how to save the game score on close card

Post by Simon » Sun Dec 23, 2012 9:14 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

ahmedinvent24BUSGdU9
Posts: 43
Joined: Mon Oct 15, 2012 6:44 pm

Re: how to save the game score on close card

Post by ahmedinvent24BUSGdU9 » Mon Dec 24, 2012 12:28 pm

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!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: how to save the game score on close card

Post by Simon » Mon Dec 24, 2012 8:18 pm

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Post Reply