Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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#
Requirements
(ame )a'er %tudio ,e"istered -!tension .ac'a"es D//*s ,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 chan"e the s'in %tudio uses from the (eneral tab found in .references. 4ou can also download a ()3 code hi"hli"ht color file.
This 1ustom 5i"h %core system allows you to store the player*s name and score to"ether with an e!tra score #alue. This could be used to record a monitory amount or the le#el or ran' attained. (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.
8age 2 o6 1#
.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#
(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. 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. 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.
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. $t will show a simple menu containin" four option buttons. &igh 'cores %electin" 5i"h %cores will ta'e you to the hi"h score room usin" a simple fade out and in effect. As the score is +ero it will display the current scores but not allow you to enter a name. Play (ame %electin" .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. $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. Testin" on other de#ices (such as i6% Android) will display a messa"e bo! into which you can enter your name instead. This is re0uired to si"nal these de#ices to produce a #irtual 'eyboard. 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; ) 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 .hone Android /inu! and )ac. $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 silently fail on the 5T)/= module. (Some +lat6orms require the S to end the a++lication e.g. )9 closing its "indo".)
8age $ o6 1#
8age % o6 1#
4ou can customi+e the score display by chan"in" the default #alues in this script.
Variable Descriptions
(aria)le score e1tra decimals de60e1tra 6name reset0scores use0commas *escri+tion The initial score !alue. The initial !alue o6 the e1tra score data B can )e numeric or a string (enclosed in quotes). 4.g. ?<o!ice?= ?Ceginner? etc. The num)er o6 decimal +laces to sho" 6or the e1tra score data B use6ul to sho" mone9 amounts (4.g. 2 "ould sho" 3 as 3.33) )ut has no e66ect i6 the e1tra score data is a string. The de6ault e1tra score !alue used "hen 6irst creating the high scores. 4.g. 3= ?<o!ice?= ?Ceginner? etc. The 6ilename to sa!e the score data as. I6 true it "ill reset all scores to their de6ault !alues= use6ul "hen de!elo+ing 9our game. *is+la9s a numeric !alue using commas as a thousands se+arator B 4.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. 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).
8age ' o6 1#
1 2 # $ % ' ,
:D Initiali&e the high score s9stem. This is called once at game start D: scr0hiscore0initiali&e(); :: Mo!ing s"i6tl9 on... room0goto0ne1t();
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*+,hiscore to your hi"h score room in the position you want it displayed and you are almost "ood to "o. There is one other thin" to edit. After closin" the hi"h score display we need the "ame to "o bac' to another room. :sually this would be a room displayin" the "ame menu. $f your menu room is called menu<room then no further editin" is re0uired. $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.
22 i6(6inish)E 2# room0goto(menu0room); :: 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. 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. The #ariable glo*al.C&,e-tra score can be used anywhere in your "ame to record your e!tra score amount.
8age , o6 1#
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. 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.
Object obj_hiscore
This is where all the ma"ic happens. When #isitin" the hi"h score room the current score is compared with those in the data structure. $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.
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. $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. 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.
8age . o6 1#
A"ain we use a loop but this time we wor' in re#erse order. Data structures start at +ero so our last position (BDth place) is at inde! E. 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!. Finally we add our new entries to the inde! position before returnin" the inde!. 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. Dependin" upon the tar"et platform / de#ice one of two thin"s happens here. IO'. $ndroid and /inPhone .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. 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. As this uses an asynchronous e#ent it will not halt the client de#ice so it is safe to use for all platforms. /indo"s. #acO'. 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. 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.
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. 1lic'in" on the te!t bo! or enterin" a character remo#es the default -nter Name. .ressin" -nter when the default te!t reads -nter Name chan"es it to No Name and concludes editin". 1lic'in" on the te!t bo! or enterin" a character si"nals the start of the input. $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. Any animations or mo#in" ob>ects in this room would continue as normal durin" input.
8age 2 o6 1#
8age 13 o6 1#
5ere we chan"ed e-tra and def,e-tra to the strin" H.ri#ateH set decimals to D and set reset<score to true8 this is important.
8age 11 o6 1#
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. %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. 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.C&,e-tra,score will now contain a te!t strin" which you can use in your "ame to set / show a player*s ran'. E-ample Use i6(+romote)E glo)al.CH0e1tra0score > ?Cor+oral?; 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.
,emember if you chan"e the e-tra score from numeric to strin" you must also chan"e the def,e-tra score to a default strin" too. The def,e-tra strin" is used the first time the hi"h score table is built. 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. %ee Cariable Descriptions for details. 8age 12 o6 1#
8age 1# o6 1#