You are on page 1of 13

Custom High Score Tutorial (Game Maker Studio

)
Written by Noel Dundas (AKA Noele) www.software4me.net/contact

Contents
Contents..........................................................................................................................1 Introduction....................................................................................................................2 Requirements..............................................................................................................2 !er!ie"........................................................................................................................# Getting Started............................................................................................................$ Resources....................................................................................................................% Customi&ing...............................................................................................................' (aria)le *escri+tions.............................................................................................' Game Start.................................................................................................................., Ho" it -orks.................................................................................................................. )/ect o)/0hiscore....................................................................................................... Scri+t scr0add0hiscore............................................................................................ )/ect o)/0in+ut0te1t.............................................................................................2 Scri+t scr0te1t0in+ut.............................................................................................13 4rror -hen 41iting the High Score.....................................................................13 5sing Strings 6or 41tra Score...................................................................................11 7++endi1 7..................................................................................................................1#

Disclaimer and Copyright Information: This tutorial document and associated files may be freely copied e!chan"ed or distributed pro#idin" no char"e is made for the actual material. $f the medium of reproduction incurs a cost you may optionally pass on such costs pro#ided you clearly state such costs are for these or your time and not for the product. This is a FREE PRODUCT. Yo may !OT sell it. Yo may !OT claim o"nership. Yo may !OT claim a thorship. Yo #$Y gi%e it a"ay. This is supplied A%&$% without warranty of any 'ind. Software4me is not affiliated to or connected with Game Maker® or with YoYo Games Ltd and whilst every endeavor is made to ensure information contained in this publication and associated files are accurate and up to date, no liability for inaccuracies or omissions may be accepted.

8age 1 o6 1#

8age 2 o6 1# .ac'a"es D//*s . This could be used to record a monitory amount or the le#el or ran' attained. Requirements (ame )a'er %tudio .e"istered -!tension . (ames created usin" (ame )a'er %tudio are not permitted to bloc' the client de#ice and to that end the 1ustom 5i"h %core system does not halt the "ame either when simply displayin" the hi"h score table or when the player enters their name.Custom High Score Tutorial (Game Maker Studio) Introduction (ame )a'er %tudio contains a built&in hi"h score system which allows you to maintain and display the top ten scores locally for the "ame. Althou"h functional it isn*t particularly attracti#e only stores the name a"ainst a score and offers little in the way of customi+in". This tutorial is aimed at allowin" you to create a custom hi"h score system which you can customi+e to suit your "ame. This 1ustom 5i"h %core system allows you to store the player*s name and score to"ether with an e!tra score #alue.e0uired 1odin" 'nowled"e (All #ersions) No None None )inimal Note2 Due to the default s'in of %tudio bein" difficult to replicate this documentation uses the ()3 s'in and code hi"hli"htin" colors. 4ou can also download a ()3 code hi"hli"ht color file. 4ou can chan"e the s'in %tudio uses from the (eneral tab found in .references.

.Custom High Score Tutorial (Game Maker Studio) Overview 6n platforms with a physical 'eyboard the custom hi"h score system inputs te!t directly into the hi"h score table at that position emulatin" an input te!t bo! as shown below.latforms without physical 'eyboards will only display a #irtual 'eyboard when e!pectin" te!t input so for these platforms the 1ustom 5i"h %core %ystem will produce a window into which the player enters their name instead of enterin" the te!t directly into the table. 8age # o6 1# .

$f you are testin" usin" Windows and the score you entered was "ood enou"h to enter the entry in the hi"h score table will be hi"hli"hted in red and you will be able to enter your name. • $t will report an error on the Windows 3 and i6% modules as it is a"ainst the conditions of their respecti#e )ar'etplaces. $t will show a simple menu containin" four option buttons. Custom High Score Tutorial (Game Maker Studio) Getting Started As supplied the 1ustom 5i"h %core will run as&is so if you ha#e not done so already import the ()7 into %tudio and run it to see it in action. &igh 'cores %electin" 5i"h %cores will ta'e you to the hi"h score room usin" a simple fade out and in effect. • $t will silently fail on the 5T)/= module. 6nly if the score was "ood enou"h to enter is it hi"hli"hted in red and the player allowed to input their name.hone Android /inu! and )ac. ) it (ame This uses the "ame<end() function to terminate the "ame which has the followin" restrictions2 • $t will wor' on Windows (includin" %team Wor'shop) Windows . Play (ame %electin" . (Some +lat6orms require the S to end the a++lication e.g. This is re0uired to si"nal these de#ices to produce a #irtual 'eyboard.) 8age $ o6 1# . Clear 'cores This option is primarily for testin"8 it deletes the current top scores and re#erts them to their default #alues 9 This offers a warnin" that it is permanent and there is no :ndo. The custom hi"h score system will also sa#e the top scores locally and re&load them when the "ame is ne!t run thus preser#in" them across "ame runs. As the score is +ero it will display the current scores but not allow you to enter a name.lay "oes to a dummy le#el room which for the purpose of this demo allows you to enter score and e!tra score #alues before "oin" to the hi"h score room.(oin" to this room with a score of +ero or a score less than that in position ten of the hi"h score table will simply display the hi"h scores. Testin" on other de#ices (such as i6% Android) will display a messa"e bo! into which you can enter your name instead. )9 closing its "indo".

4ou can alter the headin" te!t used in the hi"h score display and of course chan"e the sprites it uses. Alterin" these can be done but it would alter the display positions. The three sprites used in this e!ample can be imported or you can substitute them for your own howe#er pay attention to their si+es and ori"ins. 5owe#er alterin" the si+es or ori"ins of the sprites or si+e of the font used may re0uire you to manually alter where it draws thin"s. As you would use or create your own room to display the scores you won*t re0uire any of these rooms either. Aefore importin" resources into your "ame and you ha#en*t done so already import the 1ustom5i"hscore. The ob>ect o*+. 8age % o6 1# . 6ther than copyin" the code from the loader ob>ect you only need import the ? scripts three ob>ects and @ sprites so it won*t bloat your "ame. The font used is Arial si+e BB as this offers the most portability."m+ into %tudio so you can e!amine its codes and more importantly chec' it will do what you want. 4ou can either import it or simply copy its short code from these instructions. $f you alter this you may need to ad>ust the positionin" to "et thin"s to ali"n correctly.Custom High Score Tutorial (Game Maker Studio) Resources %ome of the resources used in this tutorial are only to demonstrate how it wor's and are not re0uired in your own "ame. All resources contained in "roups mar'ed !ot !eeded you will not need to import into your "ame. The 1ustom 5i"h %core %ystem allows for some customi+ation.loader contains some code which you will need.

I6 true it "ill reset all scores to their de6ault !alues= use6ul "hen de!elo+ing 9our game. :: e1tra score decimal +laces de60e1tra > 3. Variable Descriptions (aria)le score e1tra decimals de60e1tra 6name reset0scores use0commas *escri+tion The initial score !alue.33) )ut has no e66ect i6 the e1tra score data is a string. ?<o!ice?= ?Ceginner? etc. The initial !alue o6 the e1tra score data B can )e numeric or a string (enclosed in quotes).config scr<hiscore<confi" 1 2 # $ % ' . The 6ilename to sa!e the score data as. :: e1tra score amount decimals > 2.g. 2 13 11 12 1# 1$ 1% :: scr0hiscore0con6ig(). 3= ?<o!ice?= ?Ceginner? etc. To help a#oid namin" conflicts all "lobal #ariables used by the hi"h score system are prefi!ed with 15< (standin" for 1ustom 5i"hscore). *is+la9s a numeric !alue using commas as a thousands se+arator B 4. e1tra > 3.CH0header0name > ?<ame?. glo)al.g. 4. 4ou can customi+e the score display by chan"in" the default #alues in this script. . The de6ault e1tra score !alue used "hen 6irst creating the high scores. The num)er o6 decimal +laces to sho" 6or the e1tra score data B use6ul to sho" mone9 amounts (4. score > 3.g. :: Initial de6ault e1tra score !alue 6name > ?Scores. :: Resets score i6 true use0ccommas > true.dat?. 4.CH0header0e1tra > ?@unds?.Custom High Score Tutorial (Game Maker Studio) Customizing 6ther than replacin" the sprites used with your own most of the customi+ation can be done in a script called scr. :: @ilename to sa!e scores as reset0score > 6alse. 2 "ould sho" 3 as 3.hiscore. 8age ' o6 1# .CH0header0score > ?Score?. :: use commas in score dis+la9 :: *e6ine high score headings A Change to suit 9our requirements glo)al. (<o +arameters) :: Called to &ero scores and set custom data !ar e1tra= decimals= reset0score= de60!alue= 6name.g dra"0te1t(1=9=scr0add0commas(13$#3)) )ecomes 13=$#3 The headin"s used in the hi"h score table can also be set / chan"ed in this confi"uration script. glo)al.

6nce you ha#e added the re0uired resources to your "ame added the (ame %tart code abo#e and edited the scr<hiscore<confi" script to suit your "ame you only need to add an instance of o*+.C&.. This is called once at game start D: scr0hiscore0initiali&e(). After closin" the hi"h score display we need the "ame to "o bac' to another room. :: Mo!ing s"i6tl9 on.hiscore to your hi"h score room in the position you want it displayed and you are almost "ood to "o. $f not you will need to edit the code towards the end of the %tep -#ent in ob><hiscrore to point to the room you want to "o to. The #ariable glo*al. :: Change to suit 9our menu room name 2$ F (oin" to your hi"h score room with a score of +ero (or any score less than the one in the last place) will simply display the 5i"h %core Table.Custom High Score Tutorial (Game Maker Studio) Game Start The hi"h score system uses three data structures to contain the top ten names scores and e!tra scores. There is one other thin" to edit.. These are created by the initiali+ation script which must only be called once at the start of your "ame. $f your menu room is called menu<room then no further editin" is re0uired. o6 1# . Cisitin" this room with a score "reater than the score in the last position adds the new score at that position and allows the player to add their name. 4ou can use the (ame 'tart e#ent of an ob>ect in your first room or the Create E%ent of an ob>ect in the first room pro#idin" that room is only #isited once. :D Initiali&e the high score s9stem. 8age .e-tra score can be used anywhere in your "ame to record your e!tra score amount. 1 2 # $ % ' . 22 i6(6inish)E 2# room0goto(menu0room). room0goto0ne1t(). :sually this would be a room displayin" the "ame menu.

2$33333333333333 33333$3. Deletin" this file would ha#e the effect of it bein" re&created by the "ame the ne!t time it was run resettin" all scores bac' to their default #alues.223#.333333%3'C'1.223##313333333.223#'313333333733333 3$'.223#.333333%3'C'1.2'%. $t does this by loopin" throu"h each inde! of the data structure containin" the hi"h score #alues storin" the loop counter as the inde! and brea'in" out of the loop as soon as the score e!ceeds one in the data structure.223#1313333333. Script scr_add_hiscore $f the score was "reater than +ero the script named scr<add<hiscore is called to see if the score was hi"h enou"h to be entered or not.333333%3'C'1.2'%.223#2 2*3133333733333333333333333333333333333333333333333333333333333333333333333 3333333333333333333333333333333333333333333333333333333333333333333333333333 33333333333333333333333333333#$$33333333333333333333333333333333333333333333 33333333333333333333333333333 2*31333337333333333333333333333333$3. o6 1# . $f the score is not "ood enou"h to be entered this controller simply shows the #alues contained in the data structures and creates a 1ontinue button which is used to close the form and return to the menu.2'%.2'%.223#$31333 3333.313333333. Object obj_hiscore This is where all the ma"ic happens.313333333.2'%.333333%3'C'1.C$33333333333 3333333333.@$333333333333333333333.2'%'$23%#'*'2.223#%313333333. An update inde! "reater than &B indicates we ha#e a new entry but before storin" the new entry in our data structures we must mo#e all entries from that position onwards down one slot.2'%. When #isitin" the hi"h score room the current score is compared with those in the data structure.2$33333333333333333 33C3.333333%3'C' 1.@$3333333333333333333$3.%$3333333333333333333C3. These are sa#ed directly from our data structures so althou"h they are in strin" form openin" the data file in an e!ternal editor (li'e Notepad) mi"ht show somethin" li'e2 2*31333337333333313333333.2'%.2'% .223#2313333333.333333%3'C'1.333333%3'C'1.Custom High Score Tutorial (Game Maker Studio) How it Works The first time the "ame is run it will detect there is no scores data file so it creates some default #alues and sa#es them.@$333333333333333333323.2$333333333333333333343.313333333.$'. 8age .2'%.333333%3'C'1.2$333333333333333333333'2$3 There is of course nothin" to pre#ent a player from editin" this file e!ternally but doin" so would most probably corrupt the data for all scores.333333%3'C'1.

/indo"s. $n %tudio "ames nothin" is allowed to bloc' the client de#ice the "ame runs on so this te!t input system does not halt the "ame whilst waitin" for input. 1lic'in" on the te!t bo! or enterin" a character si"nals the start of the input.latform 6% which use #irtual 'eyboards cannot use our own te!t input method so use an asynchronous dialo" which in#o'es the de#ice to show a #irtual 'eyboard for input. We start at E and count down by one until our update inde! is reached replacin" whate#er is in each position with the #alue of the pre#ious inde!. Any animations or mo#in" ob>ects in this room would continue as normal durin" input. Custom High Score Tutorial (Game Maker Studio) Object obj_input_text The >ob of this instance is to mimic as closely as possible a te!t entry bo! allowin" the player to enter their name yet pre#entin" certain characters or too many of them spoilin" our display. 8age 2 o6 1# . . IO'. 1lic'in" on the te!t bo! or enterin" a character remo#es the default -nter Name. Dependin" upon the tar"et platform / de#ice one of two thin"s happens here. After addin" a new entry an instance of obj_input_text is created at the position attained in the hi"h score table usin" the inde! which the scr_add_hiscore script returned. $ndroid and /inPhone . #acO'. As this uses an asynchronous e#ent it will not halt the client de#ice so it is safe to use for all platforms. An inde! "reater than &B indicates we added a new score to the hi"h scores and we can now "et the player to enter their name.ressin" -nter when the default te!t reads -nter Name chan"es it to No Name and concludes editin". 0in 6% platforms with physical 'eyboards can use the te!t input system which enters te!t directly into our hi"h score table in real time. Data structures start at +ero so our last position (BDth place) is at inde! E. Finally we add our new entries to the inde! position before returnin" the inde!.A"ain we use a loop but this time we wor' in re#erse order. To pre#ent the input spoilin" our layout it "oes throu"h a few chec's to remo#e all but letters di"its and spaces and is truncated to allow a ma!imum of GD characters.

Custom High Score Tutorial (Game Maker Studio) Script scr_text_input The te!t input is handled by a script called scr_text_input. We shall howe#er outline what it does. $t is not possible to mo#e the cursor inside the te!t bo! usin" the arrow 'eys but pressin" Delete or enterin" a character when the current te!t strin" reads H-nter NameH clears the strin" completely without ha#in" to delete each one.ressin" bac'space has the effect of deletin" the last character in the strin". -ditin" ends when the player presses the -nter 'ey or selects the 6K button. $t mi"ht appear a little comple! to the untrained eye but fortunately you don*t need to worry too much about it. The script first chec's if a 'ey has been pressed since the last step e!itin" to sa#e time if none was pressed. To pre#ent the strin" o#erflowin" the te!t area the len"th of the strin" is also capped at GD characters but the player can still edit the name input. $t then chec's to see if the editin" was ended by either usin" -scape or the -nter 'ey.) 22 i6(6inish)E 2# room0goto(menu0room). $f it was and the default te!t reads H-nter NameH it is replaced by the default strin" of HNo NameH. Aecause we want to try to emulate a standard te!t bo! as much as possible we also need to allow for the delete and bac'space 'eys. (This is easy to o#erloo' and can be caused by renamin" a room. The edit bo! #anishes lea#in" the entry hi"hli"hted in red the button te!t chan"es to read 1ontinue and the input is complete. . A few more chec's are performed prior to addin" characters to the strin" to e!clude non printable characters but allow numbers lower and upper letters plus spaces. :: Change to suit 9our menu room name 2$ F 8age 13 o6 1# . Error When Exiting the High Score $f you e!perience an error when e!itin" the hi"h score display ensure you ha#e edited the %tep -#ent of ob><hiscore so the room<"oto points to your destination room.

5owe#er you may prefer to display a te!t ran' instead and the 1ustom 5i"h %core system can be confi"ured to enable this. (<o +arameters) :: Called to &ero scores and set custom data !ar e1tra= decimals= reset0score= de60!alue= 6name.=D and B.e.CH0header0name > ?<ame?.dat?. $t does not mater to () if a ds<list contains strin" or numeric data. .CH0header0e1tra > ?Rank?. score > 3. The ds<list concerned is therefore storin" a real number rather than a strin" #alue and is confi"ured to show this e!tra score data to two decimal places.config 1 2 # $ % ' .hiscore.G@4= as B. As supplied it is "eared up to display a monitory e!tra score #alue representin" funds the player collected.G@) $n order to store a strin" #alue instead we need to modify a few thin"s. :: @ilename to sa!e scores as glo)al. As supplied the hi"h score system is set up to display e!tra score data as a two decimal place monetary #alue but the followin" e!ample shows how you can use the e!tra score data to store the ran' a player attains. :: e1tra score decimal +laces de60e1tra > ?8ri!ate?.e-tra to the strin" H. 8age 11 o6 1# . e1tra > ?8ri!ate?. 2 13 11 12 1# 1$ 1% :: scr0hiscore0con6ig(). 5ere we chan"ed e-tra and def. :: use commas in score dis+la9 :: *e6ine high score headings A Change to suit 9our requirements glo)al.Custom High Score Tutorial (Game Maker Studio) Using Strings for Extra Score The 1ustom 5i"h %core %ystem uses data structures to maintain the top ten scores which unli'e arrays can contain mi!ed data types. :: Resets score i6 true 6name > ?Scores.CH0header0score > ?Score?.CH0score0commas > true. :: e1tra score amount decimals > 3.ri#ateH set decimals to D and set reset<score to true8 this is important. (i.= as E. glo)al. 6ften the e!tra score data will be numeric to show a le#el number to show an e!perience or achie#ement #alue attained or e#en coins earned. scr. :: Initial de6ault e1tra score !alue reset0score > true. glo)al. BD will show as BD.DD E.

e-tra score to a default strin" too. %ettin" reset<score to true forces the "ame to delete any e!istin" scores data file and create a new one usin" the new format.1han"in" the e!tra score data from a numeric #alue to te!t strin" would ma'e any e!istin" data no lon"er compatible causin" errors if loaded. The script scr hiscore confi! performs some rudimentary chec's to help a#oid type mismatch errors but it can still "i#e unwanted results. 8age 12 o6 1# . F :sin" the abo#e e!amples the hi"h scores would show a te!t ran' for the player which mi"ht loo' similar to this. E-ample Use i6(+romote)E glo)al. %ee Cariable Descriptions for details.C&. The def.score will now contain a te!t strin" which you can use in your "ame to set / show a player*s ran'.e-tra strin" is used the first time the hi"h score table is built. Custom High Score Tutorial (Game Maker Studio) .CH0e1tra0score > ?Cor+oral?.e-tra.emember if you chan"e the e-tra score from numeric to strin" you must also chan"e the def. After settin" it to true and runnin" you should e!it and edit the script a"ain to set it bac' to false8 lea#in" reset<scores set to true deletes the scores each time the "ame runs. The #ariable glo*al.

scr hiscore confi! 1ontains the confi"uration #ariables used by the hi"h score system. -. ob$ input te#t This handles the te!t input when enterin" a new hi"h score name. 8age 1# o6 1# . scr hiscore initiali"e 1reates the data structures to contain the custom hi"h score data populatin" them either from file (if e!istin" hi"h scores e!ist) or with default #alues. draw<te!t(! y scr<add<commas(score))8 scr add hiscore 1hec's if the current score can be added to the hi"h score list and returns the inde! of the position it added the score to or &B if it was not "ood enou"h to add.$ 'cript Use scr add commas Adds commas as thousands separator to a numerical #alue which is then returned in strin" format. )ost customi+ations can be done by chan"in" these #alues. O*+ect Use ob$ hi!hscore button This displays a close button on the hi"h score table. $t creates the close button and optionally an instance of ob><input<te!t if re0uired. $t is not used by all de#ices specifically i6% Android and Windows .hone will not use it nor will an un'nown 6%. ob$ hiscore This controls the hi"h score formattin" and display and is the only ob>ect of the three you need place in the room. scr te#t input %imulates enterin" real time te!t into an input bo! by "rabbin" one character at a time as 'eys are pressed 9 can only be used with de#ices ha#in" a physical 'eyboard.(. scr hiscore save %a#e the current hi"h scores from the data structures to a file in an encoded te!t format. scr hiscore load /oad the data structures from the data file to re&populate them.Custom High Score Tutorial (Game Maker Studio) $ppendi.