#define xorSwap //////////////////////////////////////////////////////////////// // xorSwap by Leif902 // This script is a GML implementation of // the famouse Xor Swapping Algorithm // and was written for GML by Leif902 // for Wikipedia. // It has been released into the Public Domain by the author. // This means you may use it however you wish. // // Arguments: // argument0 - The name of the first variable // as a string. // argument1 - The name of the second variable // as a string. // argument2 - Set to one if both variables are global. // If they are both local, leave off. //////////////////////////////////////////////////////////////// var a, b; a = string(argument0); b = string(argument1); if (!argument2) { if (!variable_local_exists(a) || !variable_local_exists(b)) { show_error('Error: Variable is not defined.',0); } if (variable_local_get(a) != variable_local_get(b)) { // if a does not already equal b // a = a ^ b; // b = b ^ a; // a = a ^ b; variable_local_set(a,variable_local_get(a) ^ variable_local_get(b)); variable_local_set(b,variable_local_get(b) ^ variable_local_get(a)); variable_local_set(a,variable_local_get(a) ^ variable_local_get(b)); } } else { if (!variable_global_exists(a) || !variable_global_exists(b)) { show_error('Error: Variable is not defined.',0); } if (variable_global_get(a) != variable_global_get(b)) { variable_global_set(a,variable_global_get(a) ^ variable_global_get(b)); variable_global_set(b,variable_global_get(b) ^ variable_global_get(a)); variable_global_set(a,variable_global_get(a) ^ variable_global_get(b)); } }