Jump to content


Photo

Room/Level Score Saving


  • Please log in to reply
11 replies to this topic

#1 user_4574

user_4574

    GMC Member

  • New Member
  • 6 posts
  • Version:GM:Studio

Posted 31 July 2012 - 11:26 AM

Hi,

As a relatively new user of Game Maker Studio + Android module, I would like to know how I can go about the following:

I have a variable called 'RoomTimeScore' which pauses the time the level was running for once the final object is destroyed. All good.

How can I go about coding or using the drag/drop functions to save this value out for each room basis, ala Angry Birds style? My hope is that I don't need a different variable per-room to save this out.

What I want to achieve is on Android, the user would complete a room as fast as they can - The Room Time gets saved out and the user continues to the next level, also recording how long it took for that level without overwriting the previous room time. Then when the user comes to play the game again, I'd like to be able to read from the file which was saved, to load an overlay display of how long it took the user to complete each room they have tried on a type of menu layout - again, ala Angry Birds. It would also be helpful if when re-entering a room to replay the level, the user could see the display of their previous Room Time in an effort to beat it.

Any help would be greatly appreciated. I hope this is clear enough.

If someone can provide an example code/guide of how I can do this that would be great.
  • 0

#2 cotycrg

cotycrg

    GMC Member

  • GMC Member
  • 851 posts
  • Version:GM:Studio

Posted 31 July 2012 - 01:11 PM

I don't even have to read the whole topic for this one.

ini files

Look them up in the help file in the program itself.
  • -1

#3 kburkhart84

kburkhart84

    GMC Member

  • GMC Member
  • 1631 posts
  • Version:GM:Studio

Posted 31 July 2012 - 04:37 PM

Same as I have suggested to everyone else...look at data structures. Combine them with INIs. The data structures can all be written out to a string, which you can then save and load to/from an ini file.
  • 0

#4 dasrkrain

dasrkrain

    GMC Member

  • GMC Member
  • 177 posts
  • Version:GM:Studio

Posted 31 July 2012 - 06:56 PM

Hi there user_4574,

I noticed that you asked to do this in D&D. Unfortunately I think that's impossible. Do you have any code experience or better yet GML experience?

If you have code experience I can tell you it's pretty simple to just use an array to hold the game times. Then just write the data to an ini every time you want it to save.

If you don't have any code experience just reply here letting me know and I'll write up some code for you and talk you through implementing that code properly.
  • 0

#5 user_4574

user_4574

    GMC Member

  • New Member
  • 6 posts
  • Version:GM:Studio

Posted 31 July 2012 - 10:04 PM

Hi there user_4574,

I noticed that you asked to do this in D&D. Unfortunately I think that's impossible. Do you have any code experience or better yet GML experience?

If you have code experience I can tell you it's pretty simple to just use an array to hold the game times. Then just write the data to an ini every time you want it to save.

If you don't have any code experience just reply here letting me know and I'll write up some code for you and talk you through implementing that code properly.


Hi dasrkrain,

D&D?

Anyway - I have a little code experience. But only from when I have needed to figure stuff out as-I-go type thing. I couldn't sit down and be able to write from scratch to achieve what I wanted. More trial and error after researching the relevant parts I need in order to get my result. I have much less experience in GML simply due to the fact I'm only a week into having gotten stuck into using Studio.

Naturally, any help would be appreciated.

So far, after initial guidance with using ini files to achieve my request, I have had a modicum of success. Again, any help you can offer to enhance or streamline it in any way would be good.

To further my request (if I may), I am also looking to use the countdown timer I have in each room/level, and I need it to save to /read from the ini using the appropriate room/group references. I currently have:

To Write:
ini_open("BestLevelTimes.ini");

ini_write_string("Section1",(room_get_name(room))+"String",(RoomTimeScoreString));
ini_write_real("Section1",(room_get_name(room))+"Real",(RoomTimeScoreReal));

ini_close();

(I'm storing both the string value to display on screen GUI with, and the real value to run (an eventual) calculation to work out if the time is any faster which will then update the ini.


and to read:

ini_open("BestLevelTimes.ini");

LastBestRoomTime = ini_read_string("Section1",(room_get_name(room))+"String",0);

ini_close();

What I also need is for where it says "Section1", is to write and read the group name from the folder tree in GM:S which the rest of the levels are in (Don't even know if this is possible). EG: WORLD 1 contains 3 levels. therefore scores are wrote and read as follows:

When the stopwatch is used in room0 in world 1....
[WORLD1]
room0=####
room1=####
room2=####

When the stopwatch is used in room3 in world 2.
[WORLD2]
room3=####
etc...

My INI file looks like the following:
[Section1]
room0Real=1384.000000
room0String=00:01:384

Plus I somehow need to use the REAL value of the time recorded to calculate whether the current score is any better, but also to ignore a score time of "00:00:000", otherwise it'll never update the ini !!

Something like:
if CurrentScore is less than room0Real but not 00:00:00, then output score to ini file, otherwise nothing.   (If that makes sense - just my literal thought process, not how it'd be coded obviously!!)

  • 0

#6 Serdnad

Serdnad

    GMC Member

  • GMC Member
  • 97 posts
  • Version:GM:Studio

Posted 01 August 2012 - 07:04 PM

I'm going to try and help where i can, so here goes.

D&D?

Drag and Drop

My INI file looks like the following:
[Section1]
room0Real
=1384.000000
room0String
=00:01:384

Actually, there's no need to actually make an ini file before hand, because the function for open ini will open an ini file as long as it exists, and if one doesn't, it will create one for you. However, if you want to play it safe, you can still create an empty ini file.

Plus I somehow need to use the REAL value of the time recorded to calculate whether the current score is any better, but also to ignore a score time of "00:00:000", otherwise it'll never update the ini !! Something like:
if CurrentScore is less than room0Real but not 00:00:00, then output score to ini file, otherwise nothing. (If that makes sense - just my literal thought process, not how it'd be coded obviously!!)



This would be done as so:
if(CurrentScore < room0Real && CurrentScore != 0)
{
//Saving Process
}

I believe this is what you needed? and also, you only need this one if statement, because if its false then nothing will happen.

To further my request (if I may), I am also looking to use the countdown timer I have in each room/level, and I need it to save to /read from the ini using the appropriate room/group references. I currently have:
To Write:
ini_open
("BestLevelTimes.ini");

ini_write_string
("Section1",(room_get_name(room))+"
String"
,(RoomTimeScoreString));
ini_write_real
("Section1",(room_get_name(room))+"
Real"
,(RoomTimeScoreReal));
ini_close();



I think this is a good way to make the keys, because all you have to do is copy and paste. I'm going to try and keep this in mind for future use. However, what I wanted to say is that there is no need for the addition sign and the string and everything, all you have to do is this:
To Write:
ini_open
("BestLevelTimes.ini");

ini_write_string
("Section1",(room_get_name(room)),RoomTimeScoreString);
ini_write_real
("Section1",(room_get_name(room)),RoomTimeScoreReal);
ini_close();
RoomTimeScoreString and Real are global variables, right?

Edited by Serdnad, 01 August 2012 - 07:05 PM.

  • 0

#7 user_4574

user_4574

    GMC Member

  • New Member
  • 6 posts
  • Version:GM:Studio

Posted 02 August 2012 - 10:16 AM

I didn't make the INI file before hand - I let GM:S do it, so no problem there :) I'm happy its writing out correctly!


Plus I somehow need to use the REAL value of the time recorded to calculate whether the current score is any better, but also to ignore a score time of "00:00:000", otherwise it'll never update the ini !! Something like:
if CurrentScore is less than room0Real but not 00:00:00, then output score to ini file, otherwise nothing. (If that makes sense - just my literal thought process, not how it'd be coded obviously!!)


This would be done as so:
if(CurrentScore < room0Real && CurrentScore != 0)
{
//Saving Process
}

I believe this is what you needed? and also, you only need this one if statement, because if its false then nothing will happen.


Thanks for that.

The help with the IF statement, whilst I imagine small and trivial, has helped me a lot in progressing to where I needed to get to next. Thank you!


RoomTimeScoreString and Real are global variables, right?


I believe so, yes. They are variables which only pick up the time passed in the current room but will be used in every room. They are passed over to and used in the ini_write_real/string commands and wrote out with the room name to the INI file. See included screenshot below (Along with my main question for the included screenshot.)

Posted Image

In the screenshot above, I am trying to show what I am wanting to achieve when writing out the INI file. I tried to explain this in my last post but I think I made it too convoluted and it got bypassed! :)

Anyways - Basically, I am wondering if / would like ...a way to write INI file sections using the group name which the rooms are contained in. Rather than have a bunch of IF statements that say something like - "IF roomID <= 15 then SectionID = "world 1"... IF roomID is >=16 then SectionID = "world2" etc... (again, literal in the way Im writing that, not intended to be accurate!) ... but yes, rather than that - is there a way I can just use a variable for the Section name for the INI file to grab the GROUP name whcih the rooms are contained within? It'd make my required coding much shorter! (?)


One last thing I am having difficulty in even working out how I would code, is:

I need to get a way to check how many objects of a particular name are in a room. I think it has something to do with instance_number but from reading the help file, it doesn't seem to quite fit with what I want... I have 10 objects labeled: obj_Num_1, obj_Num_2, obj_Num_3 -- obj_Num_10... not a single object which I will place 10 times.
What I would like to do is have an IF statement which counts how many objects labeled "obj_Num_*" (where * is a wildcard for the number), are in the room.
For instance, in room 1, I might only place the objects: obj_Num_1 and obj_Num_2. So i need the IF statement to know that I have only placed 2 objects in the room, but in room2, I might have objects obj_Num_1 up to obj_Num_6.

Again, thanks in advance for any help!

Edited by user_4574, 02 August 2012 - 11:52 AM.

  • 0

#8 kburkhart84

kburkhart84

    GMC Member

  • GMC Member
  • 1631 posts
  • Version:GM:Studio

Posted 02 August 2012 - 04:08 PM

I don't know of any way to access the group names, as they are just ways to organize things in the IDE. What you could do is keep the current level in a string. At the beginning of a given level, make a global variable the string you will want to put in the file. This way, each level handles itself and the file writing code only has to put global.whatever instead of figuring out which level you are in.

About the objects, what differences are there between obj_Num_1 and obj_Num_2? You may be able to optimize this using parent objects. In fact, if the objects are really different, you can still use parent objects, just to create the grouping you need,and the instance_number() function can take a parent object which includes all the child objects. But if they objects do things the same, and have events the same, then you can use parent objects even better.
  • 0

#9 cotycrg

cotycrg

    GMC Member

  • GMC Member
  • 851 posts
  • Version:GM:Studio

Posted 03 August 2012 - 01:02 AM

Honestly now at this point you're asking us to make the game for you.

Do it yourself.
  • 0

#10 Serdnad

Serdnad

    GMC Member

  • GMC Member
  • 97 posts
  • Version:GM:Studio

Posted 03 August 2012 - 06:14 AM

Sorry. Accidentally posted twice. Ignore this post. too bad I cant delete a post.

Edited by Serdnad, 03 August 2012 - 06:33 AM.

  • 0

#11 Serdnad

Serdnad

    GMC Member

  • GMC Member
  • 97 posts
  • Version:GM:Studio

Posted 03 August 2012 - 06:14 AM

I'm glad to be of assistance. lol, until now I've mostly asked for help, and so i got a little tingly inside when you said how much that had helped you. Anyways, lets see what we can do.

Anyways - Basically, I am wondering if / would like ...a way to write INI file sections using the group name which the rooms are contained in. Rather than have a bunch of IF statements that say something like - "IF roomID <= 15 then SectionID = "world 1"... IF roomID is >=16 then SectionID = "world2" etc... (again, literal in the way Im writing that, not intended to be accurate!) ... but yes, rather than that - is there a way I can just use a variable for the Section name for the INI file to grab the GROUP name whcih the rooms are contained within? It'd make my required coding much shorter! (?)


Well, in my opinion, having the rooms seperated in sections by worlds is useless, because they're all rooms, and there's simply no benefit that i can see. All you need is one section for the rooms. In fact, just one section is all you need. Now, I'm not saying you should do that, just pointing that out though. And as of my knowledge in GML (which doesn't happen to be too much), there isn't a way to do it depending on the grouping.

One last thing I am having difficulty in even working out how I would code, is:
I need to get a way to check how many objects of a particular name are in a room. I think it has something to do with instance_number but from reading the help file, it doesn't seem to quite fit with what I want... I have 10 objects labeled: obj_Num_1, obj_Num_2, obj_Num_3 -- obj_Num_10... not a single object which I will place 10 times. What I would like to do is have an IF statement which counts how many objects labeled "obj_Num_*" (where * is a wildcard for the number), are in the room. For instance, in room 1, I might only place the objects: obj_Num_1 and obj_Num_2. So i need the IF statement to know that I have only placed 2 objects in the room, but in room2, I might have objects obj_Num_1 up to obj_Num_6.



I'm not sure how to write this out in GML, so until you can figure that out, (I wish I knew), I would use D&D for that part. It's the circle wit the 1 2 and 3 under it, inside the control tab. You could switch it out later, but for now that's what I would do. Hope that solves all of your problems.

Edited by Serdnad, 03 August 2012 - 06:32 AM.

  • 0

#12 user_4574

user_4574

    GMC Member

  • New Member
  • 6 posts
  • Version:GM:Studio

Posted 03 August 2012 - 08:54 AM

Honestly now at this point you're asking us to make the game for you.

Do it yourself.


Sorry - I think you misunderstand me.
Yes, my posts/questions are verbose, but that's only because of past observation in many a forum - people often get confused and do not give much help when people asking questions are vague. I apologise if this has somehow upset you.

Nor am I asking for sections of code. Part of the issue is I need pointing in the right direction with how to go about something. I'm more than prepared to spend the hours figuring out how to construct code and my overall game on my own.
I am intelligent enough to know what I want to achieve, and what the rough process are involved in getting me to that stage, are. What isn't always apparent when starting out for the first time in these forays, is what code is needed. For example, I wouldn't know to search for "INI Files" in the help documentation when I didn't even have a clue that INI files were how Game Maker handled this time of function I was looking for - I can't type into the help-box search "save individual room data". People approach things in the way they see problems in different ways. Sometimes searching for the information one needs is frustrating and difficult.
That's why your post on telling me to search for INI files via help, pointed me in the right direction.


I'm glad to be of assistance. lol, until now I've mostly asked for help, and so i got a little tingly inside when you said how much that had helped you. Anyways, lets see what we can do.

Thank you. As I said above, it's just the pointing in the right direction that I need some times. You did help - very much.
Indeed your comment on using parent objects helped me a lot again last night - As someone with a lot of enthusiasm for my project, it is easy to miss something like this despite seeing it continuously. So I looked it up and it forced me to re-think how I constructed things. I actually went way back over my objects and set a parent for them where appropriate. And it works just how I wanted! I re-did sections of code and D&D layouts but it works great and achieves what I was wanting. There is one thing I am struggling with, but fearful of an uprising from particular forum members, I will battle through. No doubt I'll get there eventually.

With reference to checking the numbers of a particular object in a room, I managed to work this out once your post about using parents pointed me in the right direction. So YEY!... Got there eventually!

Thanks for all your help. I might PM you at some point in future if I need to bounce an idea off you or need directing towards something I'm struggling with.

Thanks again.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users