Something went wrong. Try again.
Example for an easy dialog system with many features for use in GameMaker:Studio
Something went wrong. Try again.
12 kB · 365 lines
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366<!--This Document is generated by GameMaker, if you edit it by hand then you do so at your own risk!--><object> <spriteName><undefined></spriteName> <solid>0</solid> <visible>-1</visible> <depth>-1</depth> <persistent>-1</persistent> <parentName><undefined></parentName> <maskName><undefined></maskName> <events> <event eventtype="0" enumb="0"> <action> <libid>1</libid> <id>603</id> <kind>7</kind> <userelative>0</userelative> <isquestion>0</isquestion> <useapplyto>-1</useapplyto> <exetype>2</exetype> <functionname></functionname> <codestring></codestring> <whoName>self</whoName> <relative>0</relative> <isnot>0</isnot> <arguments> <argument> <kind>1</kind> <string>///Initialize dialog when createddialog_init();dialog_import();</string> </argument> </arguments> </action> </event> <event eventtype="2" enumb="0"> <action> <libid>1</libid> <id>603</id> <kind>7</kind> <userelative>0</userelative> <isquestion>0</isquestion> <useapplyto>-1</useapplyto> <exetype>2</exetype> <functionname></functionname> <codestring></codestring> <whoName>self</whoName> <relative>0</relative> <isnot>0</isnot> <arguments> <argument> <kind>1</kind> <string>///Say the room start dialog after objects have been drawnswitch(room) { case rDemo: dialog_from_array(0, 1); break;}</string> </argument> </arguments> </action> </event> <event eventtype="3" enumb="2"> <action> <libid>1</libid> <id>603</id> <kind>7</kind> <userelative>0</userelative> <isquestion>0</isquestion> <useapplyto>-1</useapplyto> <exetype>2</exetype> <functionname></functionname> <codestring></codestring> <whoName>self</whoName> <relative>0</relative> <isnot>0</isnot> <arguments> <argument> <kind>1</kind> <string>///Deal with questions//Dealing with input is done in End Step after the instances have been activated,//allowing other instances to be affected.if(currentOption != -1 && dialog_count() == 1) { //If you do not want to ask for confirmation uncomment the following: //diaPos = string_length(dialog_get()); //Also, remove both the 'diaPos = 0;' lines from below and do the //necessary changes to the dialog_draw() event //Change options with up/down. Loop if gone past the last one if(keyboard_check_pressed(vk_down)) { diaPos = 0; //Set diaPos to 0 to make the user confirm after changing option currentOption = (currentOption + 1) % optionCount; } else if(keyboard_check_pressed(vk_up)) { diaPos = 0; currentOption = ((currentOption - 1) + optionCount) % optionCount; }} else if(!dialog_count() && currentOption != -1) { /* If you prefer, you can figure out what the question was in other ways too. This is, in my opinion, the simplest way. If you find an easier one please tell me.*/ //Save the question var question = questionAsked, answer = currentOption; //Clear values. Must be done before handling in case you want to ask another question questionAsked = ""; currentOption = -1; switch(question) { case "Are you a boy or a girl?": //I suggest copy/pasting the question to prevent typos switch(answer) { case 0: //Boy dialog_from_array(2); break; case 1: //Girl dialog_from_array(3); break; case 2: //Other dialog_from_array(4); break; case 3: //I don't know dialog_from_array(5); break; case 4: //Prefer not to say dialog_from_array(6); break; } dialog_from_array(7, 8); break; default: //Give a failure message to make debugging easier dialog_from_array(9); break; }}</string> </argument> </arguments> </action> <action> <libid>1</libid> <id>603</id> <kind>7</kind> <userelative>0</userelative> <isquestion>0</isquestion> <useapplyto>-1</useapplyto> <exetype>2</exetype> <functionname></functionname> <codestring></codestring> <whoName>self</whoName> <relative>0</relative> <isnot>0</isnot> <arguments> <argument> <kind>1</kind> <string>///Deal with string inputif(is_string(inputValue) && dialog_count() == 1) { //Change the input value //Uncomment the next line if you don't want a confirm //diaPos = 1; //Also remove the 'diaPos = 0;' line from below if(inputValue != keyboard_string) { inputValue = keyboard_string; diaPos = 0; //Reset diaPos if the string has changed to make the player confirm again }} else if(is_string(inputValue) && !dialog_count()) { /* This works essentially the same as with options. Feel free to change the method of determining the question here too. */ //Save question and answer var question = questionAsked, answer = inputValue; //Clear input values questionAsked = ""; inputValue = 0; keyboard_string = ""; switch(question) { case "What is your name?": //I would recommend validating the input in some way here if(answer != "" && string_length(answer) <= 10) { Player.name = answer; if(answer == "Luke") { dialog_from_array(10); } else { dialog_from_array(11); } } else { //If it was wrong, tell them something and ask it again dialog_from_array(12); dialog_from_array(8); } break; default: dialog_from_array(9); break; }}</string> </argument> </arguments> </action> <action> <libid>1</libid> <id>603</id> <kind>7</kind> <userelative>0</userelative> <isquestion>0</isquestion> <useapplyto>-1</useapplyto> <exetype>2</exetype> <functionname></functionname> <codestring></codestring> <whoName>self</whoName> <relative>0</relative> <isnot>0</isnot> <arguments> <argument> <kind>1</kind> <string>///Actions on regular messagesif(!dialog_count()) { //Similar to questions, but without answers. switch(lastMessage) { case "You have read this sign. Now you will die!": //I suggest copy/pasting the question to prevent typos game_end(); break; //Do nothing by default } lastMessage = ""; //Clear last message}</string> </argument> </arguments> </action> <action> <libid>1</libid> <id>603</id> <kind>7</kind> <userelative>0</userelative> <isquestion>0</isquestion> <useapplyto>-1</useapplyto> <exetype>2</exetype> <functionname></functionname> <codestring></codestring> <whoName>self</whoName> <relative>0</relative> <isnot>0</isnot> <arguments> <argument> <kind>1</kind> <string>///Update dialog variables/*Here all variables that are to be used in strings must be included.Make sure that the value actually exists before setting it.These variables can only use letters, numbers and underscores (_),similar to regular variables.*/if(instance_exists(Player)) { dialog_var("PLAYERNAME", Player.name);}</string> </argument> </arguments> </action> </event> <event eventtype="7" enumb="4"> <action> <libid>1</libid> <id>603</id> <kind>7</kind> <userelative>0</userelative> <isquestion>0</isquestion> <useapplyto>-1</useapplyto> <exetype>2</exetype> <functionname></functionname> <codestring></codestring> <whoName>self</whoName> <relative>0</relative> <isnot>0</isnot> <arguments> <argument> <kind>1</kind> <string>///Set alarm for drawing messages//Do room start messages 1 frame in so that the objects draw once//If you don't want the sprites to show up until the dialog is finished,//put the dialog_msg()'s in here.alarm[0] = 1;</string> </argument> </arguments> </action> </event> <event eventtype="8" enumb="64"> <action> <libid>1</libid> <id>603</id> <kind>7</kind> <userelative>0</userelative> <isquestion>0</isquestion> <useapplyto>-1</useapplyto> <exetype>2</exetype> <functionname></functionname> <codestring></codestring> <whoName>self</whoName> <relative>0</relative> <isnot>0</isnot> <arguments> <argument> <kind>1</kind> <string>///Draw dialogif(dialog_count()) { //Pause the game (if not already paused) if(!sprite_exists(Controller.sPause)) { game_pause(); } //Darken the surroundings if you want to draw attention to the dialog //Remove these 4 lines if you don't draw_set_alpha(0.2); draw_set_color(c_black); draw_rectangle(0, 0, window_get_width(), window_get_height(), false); draw_set_alpha(1); /****************************************************/ //Draw the sprites, box, and message on top of sPause dialog_draw();}</string> </argument> </arguments> </action> </event> <event eventtype="9" enumb="13"> <action> <libid>1</libid> <id>603</id> <kind>7</kind> <userelative>0</userelative> <isquestion>0</isquestion> <useapplyto>-1</useapplyto> <exetype>2</exetype> <functionname></functionname> <codestring></codestring> <whoName>self</whoName> <relative>0</relative> <isnot>0</isnot> <arguments> <argument> <kind>1</kind> <string>///Go to next message, or skip to the enddialog_next();//Reactivate instances if there are no more messages//Reactivating them here ensures there is no frame where they aren't drawnif(!dialog_count()) { game_unpause();}</string> </argument> </arguments> </action> </event> </events> <PhysicsObject>0</PhysicsObject> <PhysicsObjectSensor>0</PhysicsObjectSensor> <PhysicsObjectShape>0</PhysicsObjectShape> <PhysicsObjectDensity>0.5</PhysicsObjectDensity> <PhysicsObjectRestitution>0.100000001490116</PhysicsObjectRestitution> <PhysicsObjectGroup>0</PhysicsObjectGroup> <PhysicsObjectLinearDamping>0.100000001490116</PhysicsObjectLinearDamping> <PhysicsObjectAngularDamping>0.100000001490116</PhysicsObjectAngularDamping> <PhysicsObjectFriction>0.200000002980232</PhysicsObjectFriction> <PhysicsObjectAwake>-1</PhysicsObjectAwake> <PhysicsObjectKinematic>0</PhysicsObjectKinematic> <PhysicsShapePoints/></object>