package structures.data.actions.library;

import structures.data.DataAction;
import structures.data.actions.params.CheckboxParam;
import structures.data.actions.params.DoubleParam;
import structures.data.actions.params.StringParam;

public class SetGlobalVariable extends DataAction {

	public SetGlobalVariable(){
		init(new StringParam("EditVariableKey"),
				new DoubleParam("EditVariableValue"),
				new CheckboxParam("RelativeVariable?"));
	}

	@Override
	public String getTitle() {
		return "SetGlobalVariable";
	}

	@Override
	public String getDescription() {
		if((boolean) get("RelativeVariable?").getValue()){
			return String.format("change %s by %.2f", get("EditVariableKey").getValue(), get("EditVariableValue").getValue());
		}
		else{
			return String.format("make %s equal %.2f", get("EditVariableKey").getValue(), get("EditVariableValue").getValue());
		}
	}

	@Override
	protected String getSyntax() {
		return "library.set_variable('%s', %f, %b);";
	}

}

package structures.data.actions.library;

import structures.data.DataAction;
import structures.data.actions.params.CheckboxParam;
import structures.data.actions.params.GroovyParam;
import structures.data.actions.params.StringParam;

public class SetGlobalVariable extends DataAction {

	public SetGlobalVariable(){
		init(new StringParam("Variable Name"),
				new GroovyParam("Value"),
				new CheckboxParam("Relative"));
	}

	@Override
	public String getTitle() {
		return "Set Global Var";
	}

	@Override
	public String getDescription() {
		if ((boolean) get("Relative").getValue()) {
			return String.format("Change global '%s' by %s", get("Variable Name").getValue(), get("Value").getValue());
		}
		else{
			return String.format("Set global '%s' to %s", get("Variable Name").getValue(), get("Value").getValue());
		}
	}

	@Override
	public String compileSyntax() {
		if ((boolean) get("Relative").getValue()) {
			return String.format("globals.%s = globals.%s + %s;\n", get("Variable Name").getValue(), get("Variable Name").getValue(), get("Value").getValue());
		} else {
			return String.format("globals.%s = %s;\n", get("Variable Name").getValue(), get("Value").getValue());
		}
		
	}

	@Override
	protected String getSyntax() {
		return null;
	}

}

Set Global Variable action created