You are not logged in.
Pages: 1
A very small script that prevented tons of else-ifs/switches in certain situations
/// pick(val, case1, return1, case2, return2, ...)
//
// returns one of the values or undefined
//
// val - value to compare with
// case<x> - compare this to val
// return<x> - return this if case<x> equals to val
//
/// GMLscripts.com/license
function pick() {
var val = argument[0];
for(var i = 1; i < argument_count; i += 2) if argument[i] == val return argument[i+1];
return undefined;
}
Example:
enum e_TYPE { A, B, C, D }
type = e_TYPE.C;
var c = pick(type, e_TYPE.A, c_red, e_TYPE.B, c_lime, e_TYPE.C, c_orange, e_TYPE.D, c_aqua);
draw_set_color(c);
I'm on the official GM discord > maras_cz
Offline
Pages: 1