### Start Recording Keyboard and Mouse Input Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Debugging/debug_input_record.htm This example demonstrates how to start recording both keyboard and mouse input. The recorded input can later be saved using debug_input_save. ```gml debug_input_record(debug_input_filter_keyboard|debug_input_filter_mouse); ``` -------------------------------- ### Reset and Start Time Source Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Time_Sources/time_source_reset.htm This example demonstrates how to reset a Time Source and then immediately start it again. This is commonly used in the Room Start event to ensure a timed event begins correctly when a new room loads. ```gml time_source_reset(global.spawn_time_source); time_source_start(global.spawn_time_source); ``` -------------------------------- ### Execute Script Action Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/Drag_And_Drop/Drag_And_Drop_Reference/Common/Execute_Script.htm This example demonstrates calling a user-defined function with two arguments to get a random position within the room. No return value is captured. ```Drag and Drop Execute Script Script: random_position Argument0: 0 Argument1: 1 Target: ``` -------------------------------- ### GML string_ord_at Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Strings/string_ord_at.htm This example demonstrates how to get the character code of the seventh character in a string using string_ord_at. The index starts at 1. ```gml str = "Hello World"; char_code = string_ord_at(str, 7); ``` -------------------------------- ### GML Example: Initializing Audio System Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_system_is_initialised.htm This example demonstrates how to check if the audio system is initialised and perform first-time setup when it becomes available. It sets up a custom audio bus and emitter once the system is ready. ```gml /// @description Initially, the audio system is not initialised audio_initialised = false; em_emitter = -1; bus_special_effects = -1; /// @description Check until the system is initialised if !audio_initialised && audio_system_is_initialised() { audio_initialised = true; // First-time initialization bus_special_effects = audio_bus_create(); bus_special_effects[0] = audio_effect_create(AudioEffectType.Reverb1); em_emitter = audio_emitter_create(); audio_emitter_bus(em_emitter, bus_special_effects); } if (audio_initialised) { // The audio system can be used here // ... } ``` -------------------------------- ### Example: Start Following Path on Key Press Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/Drag_And_Drop/Drag_And_Drop_Reference/Paths/Start_Following_Path.htm This example demonstrates how to make an instance follow a path when a specific key is pressed. It uses absolute positioning and restarts the path upon reaching the end. ```drag and drop Start Following Path Path: path_asset_name Speed: 2 On End: Restart Absolute: True ``` -------------------------------- ### Get Gamepad GUID and Description Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Game_Input/GamePad_Input/gamepad_get_guid.htm This example demonstrates how to retrieve both the GUID and the description of a gamepad, then combine them into a single string stored in a global variable. This combined string can be used for controller remapping. ```gml var _guid = gamepad_get_guid(global.PadIndex); var _desc = gamepad_get_description(global.PadIndex); global.GamepadID = _guid + "," + _desc; ``` -------------------------------- ### Setting Up a Particle System using Code Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Drawing/Particles/Particle_Systems/part_system_create.htm This snippet demonstrates creating a particle system, adding an emitter, configuring its region and distribution, defining a particle type with a disk shape, and setting the emitter to stream particles. It also shows the necessary cleanup in the Clean Up event. ```gml part_sys = part_system_create(); part_emitter = part_emitter_create(part_sys); part_emitter_region(part_sys, part_emitter, 0, room_width, 0, room_height, ps_shape_rectangle, ps_distr_linear); part_type = part_type_create(); part_type_shape(part_type, pt_shape_disk); part_emitter_stream(part_sys, part_emitter, part_type, 2); ``` ```gml part_system_destroy(part_sys); part_type_destroy(part_type); ``` -------------------------------- ### Get and Reset Sequence Playhead Position Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/Sequence_Layers/layer_sequence_get_headpos.htm This example checks if the playhead of a sequence element is not at the beginning (frame 0). If it's not, it resets the playhead to frame 0. This is useful for ensuring sequences start from the beginning under certain conditions. ```gml if (layer_sequence_get_headpos(title_sequence) != 0) { layer_sequence_headpos(title_sequence, 0); } ``` -------------------------------- ### Get Color Value Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Drawing/Colour_And_Alpha/colour_get_value.htm This example demonstrates how to get the luminosity of a predefined color (c_teal) and use it to set a new random color with the same luminosity. ```gml col = make_colour_hsv(random(255), 255, colour_get_value(c_teal)); ``` -------------------------------- ### GML Example: Setting Wallpaper Configuration Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Live_Wallpapers/wallpaper_set_config.htm This example demonstrates how to create and pass a complex configuration array to the wallpaper_set_config function. It includes nested sections and various option types. ```gml var _config = [ { type: "section", name: "animation", label: "Animation", children: [ { type: "range", name: "speed", label: "Rotation speed", value: 50, min: 0, max: 200, step: 25 }, { type: "boolean", name: "clockwiseRotation", label: "Clockwise rotation", value: false }, { type: "boolean", name: "pause", label: "Pause animation", value: true } ] }, { type: "section", name: "colours", label: "Colours", children: [ { type: "colour", name: "blendColor", label: "Blend colour", value: #FA1E4E }, { type: "range", name: "blendAlpha", label: "Blend alpha", value: 100 } ] } ]; wallpaper_set_config(_config); ``` -------------------------------- ### Get Display Height Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Cameras_And_Display/display_get_height.htm This example shows how to get the display height and store it in a variable. ```gml myheight = display_get_height(); ``` -------------------------------- ### GML: Compute and Start Potential Path Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Movement_And_Collisions/Motion_Planning/mp_potential_path.htm This example demonstrates creating a new path, computing a potential path to the player's position while checking for collisions with all instances, and then starting the instance along this path. It ensures the instance begins moving even if a complete path is not found. ```gml path = path_add(); mp_potential_path(path, obj_Player.x, obj_Player.y, 3, 4, 0); path_start(path, 3, 0, 0); ``` -------------------------------- ### GML date_date_string Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_date_string.htm This example demonstrates how to get the current date as a formatted string and display it. It uses date_current_datetime() to get the current date and time, then formats the date part using date_date_string(). ```gml str = date_date_string(date_current_datetime()); draw_text(32, 32, str); ``` -------------------------------- ### Setting Audio Channels Based on OS Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_channel_num.htm This example demonstrates how to configure the number of audio channels based on the operating system or browser environment to optimize performance. ```gml switch (os_browser) { case browser_not_a_browser: switch (os_type) { case os_windows: case os_macosx: audio_channel_num(200); break; default: audio_channel_num(64); break; } break; default: audio_channel_num(16); break; } ``` -------------------------------- ### GML Example: Get Audio Loop Status Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/Audio_Loop_Points/audio_sound_get_loop.htm This example demonstrates how to get the loop status of a sound asset. It calls audio_sound_get_loop with a sound asset index and stores the boolean result in a variable. ```gml var _loop = audio_sound_get_loop(snd_car); ``` -------------------------------- ### Load Buffer Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/Drag_And_Drop/Drag_And_Drop_Reference/Files/Load_Buffer.htm This example demonstrates how to use the Load Buffer action. It checks for an existing save file, loads it if present, or creates, writes to, and saves a new file if it does not exist. ```drag_and_drop var buffer_data = buffer_create(1, buffer_fixed, 1); if (file_exists("save.sav")) { buffer_load(buffer_data, "save.sav"); } else { buffer_write(buffer_data, 0, 0); buffer_save(buffer_data, "save.sav"); } ``` -------------------------------- ### Get Current Weekday Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_weekday.htm This example demonstrates how to get the current day of the week and store it in a variable. ```gml myweekday = date_get_weekday(date_current_datetime()); ``` -------------------------------- ### Particle System Following an Instance with Global Space Enabled Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Drawing/Particles/Particle_Systems/part_system_global_space.htm This example demonstrates setting up a particle system to follow an instance, leaving a trail. It configures the particle system to use global space, defines a particle type, and streams particles from an emitter. The particle system's position and angle are updated each step to match the instance's movement. ```gml /// Create Event ps = part_system_create(); part_system_global_space(ps, true); pe = part_emitter_create(ps); pt = part_type_create(); part_type_shape(pt, pt_shape_flare); part_type_direction(pt, 0, 360, 0, 0.3); part_type_speed(pt, 0.1, 0.2, 0, 0.01); part_type_scale(pt, 0.3, 0.3); part_emitter_stream(ps, pe, pt, 2); /// Step Event part_system_position(ps, x, y); part_system_angle(ps, direction); /// Clean Up Event part_emitter_destroy(pe); part_system_destroy(ps); part_type_destroy(pt); ``` -------------------------------- ### Get Current Hour Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_hour.htm This example demonstrates how to get the current hour of the day and store it in a variable. ```gml myhour = date_get_hour(date_current_datetime()); ``` -------------------------------- ### GML path_start Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Paths/path_start.htm This example demonstrates how to make the calling instance follow a path. The path is specified by the 'path' variable, with a speed of 4 pixels per step. The instance will follow the path relative to its current position and reverse direction upon reaching the end. ```gml path_start(path, 4, path_action_reverse, false); ``` -------------------------------- ### Get Current Day Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_day.htm This example demonstrates how to get the current day of the month and store it in a variable. ```gml myday = date_get_day( date_current_datetime() ); ``` -------------------------------- ### Get Tile Set Name GML Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Tilsets/tileset_get_name.htm This example demonstrates how to get the string name of a tile set associated with a specific layer. The returned name can then be used to obtain the tile set's index. ```gml var _l = layer_get_id("tilemap_trees"); var _m = layer_tilemap_get_id(_l); var _t = tilemap_get_tileset(_m); tileset_name = tileset_get_name(_t); ``` -------------------------------- ### Setting Up a Particle System using an Asset Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Drawing/Particles/Particle_Systems/part_system_create.htm This snippet shows how to create a particle system instance directly from a pre-defined Particle System Asset. The corresponding cleanup function is also included. ```gml part_sys = part_system_create(ps_fireworks); ``` ```gml part_system_destroy(part_sys); ``` -------------------------------- ### Get Gamepad Axis Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/Drag_And_Drop/Drag_And_Drop_Reference/Gamepad/Get_Gamepad_Axis.htm This example demonstrates how to get the horizontal and vertical axis values from the left stick of a gamepad and store them in temporary variables. These values are then used to set the instance's direction. ```drag and drop Create Temp Variable: horizontal_axis Create Temp Variable: vertical_axis Gamepad Get Axis(0, Left Stick, Horizontal, horizontal_axis) Gamepad Get Axis(0, Left Stick, Vertical, vertical_axis) Set Direction(horizontal_axis, vertical_axis) ``` -------------------------------- ### GML camera_create Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Cameras_And_Display/Cameras_And_Viewports/camera_create.htm Creates a new camera, assigns it to view[0], and sets its view and projection matrices using matrix_build_lookat and matrix_build_projection_ortho. ```gml view_camera[0] = camera_create(); var _viewmat = matrix_build_lookat(640, 240, -10, 640, 240, 0, 0, 1, 0); var _projmat = matrix_build_projection_ortho(640, 480, 1.0, 32000.0); camera_set_view_mat(view_camera[0], _viewmat); camera_set_proj_mat(view_camera[0], _projmat); ``` -------------------------------- ### Get Current Week Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_week.htm This example demonstrates how to get the current week number using the date_get_week function. ```gml myweek = date_get_week(date_current_datetime()); ``` -------------------------------- ### Creating and Assigning an Audio Bus Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/Audio_Effects/audio_bus_create.htm This example demonstrates how to create a new audio emitter and an audio bus, then assign the emitter to the bus and play a sound on it. This allows for custom audio effect chains. ```gml emitter1 = audio_emitter_create(); emitter1_bus = audio_bus_create(); audio_emitter_bus(emitter1, emitter1_bus); audio_play_sound_on(emitter1, snd_Ambience, true, 100); ``` -------------------------------- ### Setting Room Dimensions and Persistence Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/room_set_height.htm This example demonstrates how to create a new room, set its width and height, and configure its persistence using GML functions. ```gml global.myroom = room_add(); room_set_width(global.myroom, 640); room_set_height(global.myroom, 480); room_set_persistent(global.myroom, false); ``` -------------------------------- ### Get Parent Node Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Flex_Panels/Function_Reference/flexpanel_node_get_parent.htm This example demonstrates how to get the parent of a given node and store it in a local variable. ```gml var _parent = flexpanel_node_get_parent(_node); ``` -------------------------------- ### Get Path Length Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Paths/path_get_length.htm This example demonstrates how to get the total pixel length of a path using its index. ```gml path_len = path_get_length(pth_AI); ``` -------------------------------- ### buffer_set_surface Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Buffers/buffer_set_surface.htm This example demonstrates creating a surface, clearing it, and then copying its data into a buffer using buffer_set_surface. It assumes the buffer and surface formats are compatible. ```gml if (!surface_exists(surf1)) { surf1 = surface_create(200, 200); surface_set_target(surf1); draw_clear_alpha(c_white, 0); surface_reset_target(); if (buffer_exists(buff1)) { buffer_set_surface(buff1, surf1, 0) } } ``` -------------------------------- ### Populate and Use Skin List Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Sprites/Skeletal_Animation/Skins/skeleton_skin_list.htm This example demonstrates how to create a DS list, populate it with skin names from a sprite, select a random skin, apply it to the instance, and then destroy the list. ```gml var list = ds_list_create(); skeleton_skin_list(sprite_index, list); var num = ds_list_size(list); skeleton_skin_set(list[| irandom(num - 1)]); ds_list_destroy(list); ``` -------------------------------- ### Get Current Second GML Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_second.htm This example demonstrates how to get the current second of the day using the date_get_second function. ```gml mysecond = date_get_second(date_current_datetime()); ``` -------------------------------- ### Get Current Hour of Year Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_hour_of_year.htm This example demonstrates how to get the current hour of the year using the date_get_hour_of_year function. ```gml myhouryear = date_get_hour_of_year(date_current_datetime()); ``` -------------------------------- ### GML Example: Adding Sounds to a Sync Group and Playing Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/Audio_Synchronisation/audio_play_in_sync_group.htm This example demonstrates how to create a new audio synchronization group, add multiple sounds to it, and then start playback of the group. It's useful for synchronizing multiple audio assets. ```gml sg = audio_create_sync_group(true); audio_play_in_sync_group(sg, sound1); audio_play_in_sync_group(sg, sound2); audio_play_in_sync_group(sg, sound3); audio_play_in_sync_group(sg, sound4); audio_start_sync_group(sg); ``` -------------------------------- ### Copying a DS Queue Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Data_Structures/DS_Queues/ds_queue_copy.htm This example demonstrates how to create a new instance, initialize a DS queue within it, and then copy the contents of the current instance's queue into the new instance's queue. ```gml with (instance_create_layer(x, y, "Enemies", obj_Enemy)) { queue = ds_queue_create(); ds_queue_copy(queue, other.queue); } ``` -------------------------------- ### Get Current Month Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_month.htm This example demonstrates how to get the current month using the date_get_month function and store it in a variable. ```gml mymonth = date_get_month(date_current_datetime()); ``` -------------------------------- ### Get Mouse Y Position Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Cameras_And_Display/display_mouse_get_y.htm This example demonstrates how to get the mouse's Y coordinate relative to the display and store it in a variable. ```gml my_y = display_mouse_get_y(); ``` -------------------------------- ### GML zip_create Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/File_Handling/Encoding_And_Hashing/zip_create.htm This example demonstrates creating a new ZIP file, adding two files (one in a subdirectory), and saving it to disk. ```gml var _zip = zip_create(); zip_add_file(_zip, "new.txt", "new.txt"); zip_add_file(_zip, "sounds/snd_attack_arc_01.wav", "snd_attack_arc_01.wav"); zip_save(_zip, "upload.zip"); ``` -------------------------------- ### Get Days in Current Month Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_days_in_month.htm This example demonstrates how to get the number of days in the current month using the date_days_in_month function. ```gml days = date_days_in_month(date_current_datetime()); ``` -------------------------------- ### Create TCP Socket and Connect Raw Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Networking/network_connect_raw.htm This example demonstrates creating a new TCP socket and then attempting to establish a raw connection to a specified URL and port. ```gml client = network_create_socket(network_socket_tcp); network_connect_raw(client, "www.macsweeneygames.com", 6510); ``` -------------------------------- ### Get Buffer Type Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Buffers/buffer_get_type.htm This example demonstrates how to get the type of a buffer stored in the 'buff' variable and assign it to the 'type' variable. ```gml type = buffer_get_type(buff); ``` -------------------------------- ### GML - Setting Asset Gain and Playing with Custom Gain Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_sound_gain.htm This example first sets the default gain for a sound asset and then plays a new instance of that sound with a different, higher gain value. It shows how to affect the asset's default gain and control the gain of individual instances. ```gml audio_sound_gain(snd_fountain, 0.5); var _snd = audio_play_sound(snd_fountain, 0, true, 2); ``` -------------------------------- ### Get Current Year in GML Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_year.htm This example demonstrates how to get the current year using date_get_year and date_current_datetime(). It assigns the result to a variable. ```gml myyear = date_get_year(date_current_datetime()); ``` -------------------------------- ### Set Audio Pitch Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/Drag_And_Drop/Drag_And_Drop_Reference/Audio/Set_Audio_Pitch.htm This example demonstrates how to get the current pitch of a sound, check for a key press, and if detected, adjust and set the sound's pitch before playing it. It uses a temporary variable to store and modify the pitch. ```GML Visual /// @description Set Audio Pitch Example // Get the current pitch of the sound and store it in a temporary variable var _current_pitch = audio_get_pitch(snd_Example); // Check if the 'up' key is pressed if (keyboard_check(vk_up)) { // If the current pitch is less than 2, stop the sound if (_current_pitch < 2) { audio_stop_sound(snd_Example); // Increase the pitch variable by 0.1 _current_pitch += 0.1; // Set the new pitch for the sound audio_set_pitch(snd_Example, _current_pitch); // Play the sound with the new pitch audio_play_sound(snd_Example, 1, false); } } ``` -------------------------------- ### GML: Calculating and Following an MP Grid Path Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Movement_And_Collisions/Motion_Planning/mp_grid_path.htm This example demonstrates creating an MP grid, adding obstacles, and then calculating a path for each enemy instance to follow towards the player. It initializes the path asset, calls mp_grid_path, and if successful, starts the instance moving along the path. ```gml global.grid = mp_grid_create(0, 0, room_width div 32, room_height div 32, 32, 32); mp_grid_add_instances(global.grid, obj_wall, false); with (obj_enemy) { path = path_add(); if (mp_grid_path(global.grid, path, x, y, obj_player.x, obj_player.y, 1)) { path_start(path, 0, 3, 0); } } ``` -------------------------------- ### Get Current Second of Year Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_second_of_year.htm This example demonstrates how to get the current second of the year using the date_get_second_of_year function and the date_current_datetime function. ```gml mysecondyear = date_get_second_of_year(date_current_datetime()); ``` -------------------------------- ### Get Gamepad Button Count Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Game_Input/GamePad_Input/gamepad_button_count.htm This example shows how to get the number of buttons for the gamepad in device slot 0 and store it in a variable. ```gml b_num = gamepad_button_count(0); ``` -------------------------------- ### Compressing and Saving Buffer Data Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Buffers/buffer_compress.htm This example demonstrates how to create a buffer, write string data into it, compress the buffer's content, save the compressed data to a file, and then delete both buffers. It utilizes buffer_create, buffer_write, buffer_compress, buffer_tell, and buffer_save. ```gml var _srcBuff = buffer_create(1024, buffer_grow, 1); buffer_write(_srcBuff, global.DataString); var _cmpBuff = buffer_compress(_srcBuff, 0, buffer_tell(_srcBuff)); buffer_save(_cmpBuff, "Player_Save.sav"); buffer_delete(_srcBuff); buffer_delete(_cmpBuff); ``` -------------------------------- ### Get Listener Count Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/Audio_Listeners/audio_get_listener_count.htm This example demonstrates how to get the number of available audio listeners and store it in a global variable for later use. ```gml global.listener_num = audio_get_listener_count(); ``` -------------------------------- ### GML: Playing and Re-playing a Sound Asset Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Audio/audio_sound_get_asset.htm This example demonstrates how to play a sound, retrieve its associated asset, and then play the sound again using that asset. It first plays a sound in the Create event and stores the instance ID. Then, in a Key Press event, it retrieves the sound asset and plays it again if the asset is valid. ```gml sound = audio_play_sound(Sound1, 1, 0); ``` ```gml var _asset = audio_sound_get_asset(sound); if (audio_exists(_asset)) { audio_play_sound(_asset, 1, 0); } ``` -------------------------------- ### Example: Get and Modify Tile Data Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/Drag_And_Drop/Drag_And_Drop_Reference/Tiles/Get_Tile_Data_At_Pixel.htm This example demonstrates how to get tile data at the mouse position, modify it (rotate the tile), and then update the tile-map layer with the modified data. This is typically used in response to user input like a mouse click. ```Drag and Drop ![Get Tile Data At Pixel Example](../../../assets/Images/Scripting_Reference/Drag_And_Drop/Reference/Tiles/e_Tiles_Set_Tile_Data_At_Pixel.png) ``` -------------------------------- ### GameMaker Language: Build Look-At Matrix and Set Camera Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Matrix_Functions/matrix_build_lookat.htm This example demonstrates how to create a look-at view matrix and an orthographic projection matrix, then apply them to a camera. It's useful for setting up the camera's perspective in a 3D environment. ```gml viewmat = matrix_build_lookat(640, 240, -10, 640, 240, 0, 0, 1, 0); projmat = matrix_build_projection_ortho(640, 480, 1.0, 32000.0); camera_set_view_mat(view_camera[0], viewmat); camera_set_proj_mat(view_camera[0], projmat); ``` -------------------------------- ### Get Particle Element Y Position Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Rooms/Particle_System_Layers/layer_particle_get_y.htm This example demonstrates how to get the y offset of a particle system element. It first retrieves the element's ID using layer_particle_get_id and then uses layer_particle_get_y to get its y-coordinate. ```gml var _element_id = layer_particle_get_id("Particles", "particle_smoke"); var _y = layer_particle_get_y(_element_id); ``` -------------------------------- ### Display Build Date and Version Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/OS_And_Compiler/GM_build_date.htm This example demonstrates how to display the game's version and its compilation date and time using GM_build_date and GM_version constants. ```gml draw_text(32, 32, date_time_string(GM_build_date)); draw_text(32, 64, "v" + GM_version); ``` -------------------------------- ### GML frac Example Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Number_Functions/frac.htm This example demonstrates how to use the `frac` function to get the fractional part of a number. The result is assigned to the variable `val`. ```gml val = frac(3.4); ``` -------------------------------- ### Creating and Playing an Audio Queue Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/The_Asset_Editors/Object_Properties/Async_Events/Audio_Playback.htm This snippet demonstrates how to create an audio queue, add multiple audio buffers to it, and then start playback. It initializes a queue with 10 buffered sounds. ```gml audio_queue = audio_create_play_queue(buffer_s16, 11052, audio_mono); for (var i = 0; i < 10; i++)    {    audio_queue_sound(audio_queue, audio_buffer[i], 0, buffer_get_size(audio_buffer[i]));    } audio_play_sound(audio_queue, 0, true); ``` -------------------------------- ### Perform Begin Step Event Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Asset_Management/Objects/Object_Events/event_perform.htm This example shows how to execute the 'Begin Step' event of an object. It uses the ev_step event type and the ev_step_begin constant to specify the sub-event. ```gml event_perform(ev_step, ev_step_begin); ``` -------------------------------- ### Get User Sponsor ID Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/UWP_And_XBox_Live/Users_And_Accounts/xboxlive_sponsor_for_user.htm This example demonstrates how to get the user ID for a gamepad slot and then use it to retrieve the sponsor ID for that user. ```gml var _uid = xboxlive_user_for_pad(0); sponsor = xboxlive_sponsor_for_user(_uid); ``` -------------------------------- ### Get Current Minute of Year in GML Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Maths_And_Numbers/Date_And_Time/date_get_minute_of_year.htm This example demonstrates how to get the current minute of the year using the date_get_minute_of_year function and the date_current_datetime function. ```gml myminuteyear = date_get_minute_of_year(date_current_datetime()); ``` -------------------------------- ### Creating and Saving a GIF Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Cameras_And_Display/gif_open.htm This example demonstrates how to open a GIF, add frames from the application surface, and then save the GIF. It includes logic to control the number of frames and when to start/stop recording. ```GML if (save_gif == true) { if (count == 0) { gif_image = gif_open(room_width, room_height); } else if (count < 30) { gif_add_surface(gif_image, application_surface, 6/100); } else { gif_save(gif_image, "GameCapture.gif"); count = 0; save_gif = false; } count++; } ``` -------------------------------- ### Get Flex Panel Node Position Type Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Flex_Panels/Function_Reference/Styling_Functions/flexpanel_node_style_get_position_type.htm This example demonstrates how to get the position type of a Flex Panel Node and store it in a variable. ```gml var _position_type = flexpanel_node_style_get_position_type(_node); ``` -------------------------------- ### Example: Creating and Populating a Map Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/Drag_And_Drop/Drag_And_Drop_Reference/Data_Structures/Create_Map.htm This example demonstrates how to create a map data structure, store its index in a variable, and then add key-value pairs to it using the 'Map Add' action. ```gml /// @description Create Map Example /// @param target The target variable to store the map index in // Creates a new map and stores its index in 'myMap' // Then adds two key-value pairs to the map. ``` -------------------------------- ### Creating a TCP Server and Finding an Available Port Source: https://github.com/yoyogames/gamemaker-manual/blob/develop/Manual/contents/GameMaker_Language/GML_Reference/Networking/network_create_server.htm This example demonstrates how to create a TCP server and attempts to find an available port if the initial port (6510) is already in use. It sets the maximum number of clients to 32. ```gml var port = 6510; server = network_create_server(network_socket_tcp, port, 32); while (server < 0 && port < 65535) { port++ server = network_create_server(network_socket_tcp, port, 32); } ```