GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2022-12-28 17:42:06

maras
Member
Registered: 2021-04-25
Posts: 28
Website

pick

A very small script that prevented tons of else-ifs/switches in certain situations

Expand/// 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:

Expandenum 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

Board footer

Powered by FluxBB