Skip to content

Instantly share code, notes, and snippets.

View PoppyWorks's full-sized avatar

Poppy Works PoppyWorks

View GitHub Profile
@PoppyWorks
PoppyWorks / string_button()
Last active April 1, 2019 16:05
Replace common terms with special symbols for platform buttons
///string_button(string)
var str = argument0;
///XO - PlayStation Controller Keys
if os_type == (os_psvita || os_ps4)
{
str = string_replace_all(str,"CONFIRM","➀");
str = string_replace_all(str,"CANCEL","➁");
str = string_replace_all(str,"BUTTON3","➂");
str = string_replace_all(str,"BUTTON4","➃");
@PoppyWorks
PoppyWorks / button_ui_held
Last active August 22, 2018 18:51
GML Script. Should be run on an object that you wish to have the player click. Create an obj_cursor for console users and move it around via the gamepad to have this script work for both gamepad. mouse, and touchscreen users.
///button_ui_held(device number, button)
var me = id;
return position_meeting(mouse_x,mouse_y,me) && mouse_check_button(mb_left) || place_meeting(x,y,obj_cursor) && gamepad_button_check(argument0,argument1)
@PoppyWorks
PoppyWorks / setup_language
Last active August 16, 2018 19:08
GML Script. This should allow the use of any language files to be placed in an ISO639 standard named folder. The game should react accordingly based on the user's OS language. Alternatively, you can change global.language manually to test this feature.
//build fonts
//--------------------------
global.fnt_textbox = font0;
//get OS Language
//--------------------------
global.language = os_get_language();
//Load appropriate langage table for UI via JSON
//THING HERE
@PoppyWorks
PoppyWorks / setup_audio
Last active August 14, 2018 10:49
GML Script. This sets up all listeners available on a target platform. In the case of PS4, you can use this to play audio on a DS4 speaker. Run before running anything using audio_play_sound_on();. In addition, this fixes GMS games being too quiet or low volume on consoles. Best run in a Create event.
///setup_audio();
var lc = audio_get_listener_count();
var masks;
masks[0] = 0;
masks[1] = 0;
masks[2] = 0;
masks[3] = 0;
alert("Number of Audio Listeners: " + string(lc),0)
@PoppyWorks
PoppyWorks / setup_input
Created August 13, 2018 22:16
GML script. Sets up our globals for all input functions in other scripts posted here.
///setup_input(run in a create event!)
//gamepads
var gp_num = gamepad_get_device_count();
for (var i = 0; i < gp_num; i++;)
{
if gamepad_is_connected(i)
{
alert("DEBUG: "+ string(gamepad_get_description(i)),0)
}
else
@PoppyWorks
PoppyWorks / gamepad_color
Created July 23, 2018 00:58
GML Script for changing the color of a DS4 gamepad. Will likely only function on PS4. Will return true upon completion of the color change.
///gamepad_color(device,color,time)
var device = argument0;
var color = argument1;
var time = argument2; //(use something like .01)
if color != global.gpColor
{
var led = merge_color(global.gpColor,color,global.gpColorFader)
global.gpColorFader += time;
gamepad_set_color(device,led)
@PoppyWorks
PoppyWorks / input_change
Last active August 14, 2018 01:00
GML Script. Knows what OS you are using, and if you are using a gamepad or keyboard/mouse. Use bootstrap after input_change(). Bootstrapper ensures that a gamepad is connected before allowing the user to swap over to gamepad input from Keyboard/mouse.
///PC users or PS4 Input
if os_type == os_windows || os_ps4 || os_xboxone
{
if gamepad_button_check_any(global.gpDevice)
{
global.KBMuser = false;
}
if keyboard_check(vk_anykey) || mouse_check_button(mb_any)
{
global.KBMuser = true;
@PoppyWorks
PoppyWorks / button_check
Last active August 14, 2018 00:58
GML Script. Used in step after setup_inputs has been used. This is a generic input script that can change back and forth from keyboard/mouse to gamepad via the input_change swapper. Example: button_check(0,global.confirm);
///button_check(device number, button)
return keyboard_check(argument1) || gamepad_button_check(argument0,argument1)
@PoppyWorks
PoppyWorks / gamepad_button_check_any
Created August 13, 2018 22:18
GML Script. Checks to see if the device number (argument0) was interacted with at all. Used in input_change() to know to swap inputs!
///gamepad_button_check_any(device)
device = argument0;
for ( var i = gp_face1; i < gp_axisrv; i++ )
{
if ( gamepad_button_check(device , i ) ) return i;
}
return false;
@PoppyWorks
PoppyWorks / alert
Last active July 27, 2018 02:02
GML Script. A basic multi-level wrapper for the debug/message system used in Gamemaker Studio. Alert will be seen throughout our samples here. When shipping, you can comment the entire script out easily!
///alert(level[0 to 3],message)
var level = argument0;
var text = argument1;
{
switch (argument0)
{
case 0: show_debug_message("DEBUG: "+text); break;
case 1: show_debug_message("ERROR: "+text); break;
case 2: show_message("ALERT: "+text); break;