Feature Request: Allow declare structures like subroutines

I have an request, allow us to declare an custom data type, instead only array with one value type in it.

For example, create ExampleData structure that stores two numbers one about health and another damagePerTime

structures {
  ExampleData: {
    health: Number;
    damagePerTime: Number;
  }
}

And we can use in global/player variables:

And we can store into player/global variable:

  • Set Player Variable(A, Custom Struct(ExampleData))
  • Modify Struct(ExampleData, health, Player Variable(A), 150)

Also we can use values in actions (for example damage action):

structures {
	ExampleData: {
		health: Number;
		damagePerTime: Number;
	}
};

rule("Damage player by struct value")
{
	event 
	{
		Ongoing - Player;
		All;
		All;
	}
	
	conditions 
	{
		Is Alive(Event Player) == True;
	}
	
	acitons
	{
	  Damage(Struct Field(ExampleData, damagePerTime, Player Variable(Event Player, A))
	  Wait(0.25);
	  Loop;
	}
}

Value: Struct Field(<name>, <field name>, <instance>)

  • name: Struct name
  • field name: Struct field name
  • instance: struct instance in global/player variable/value in array.

Example:

conditions
{
  Struct Field(ExampleData, damagePerTime, Player Variable(Event Player, A) != 10;
}

Action: Modify Struct (<name>, <field name>, <instance>, <value>

  • name: Struct name
  • field name: Struct field name
  • instance: Struct instance stored in player/global variable and/or value in array.
  • value: New value to field.

Example:

Modify Struct(ExampleData, health, PlayerVariable(A), 200)

Action: Initialize Struct(<name>)

  • name: Struct name

Example

Set Global Variable(A, Initialize Struct(ExampleData));

- And allow to declare multi-dimentional arrays.
- And allow declare array of structs.
1 Like

You say that Initialize Struct is an action yet you used it like a value. Would this work better?:

actions
{
  Initialize Struct(ExampleData);
  Set Global Variable(A, Last Created Struct);
}

with Last Created Struct being a new value.

1 Like

Yes

~17 characteres requied~

Yeah and unions too please (jk they’d be useless in OW)

Honestly if you’re gonna go as far as proposing structs in the workshop might as well go the full mile and do classes…

classes and structs probably won’t happen without “multidimensional arrays”. i put that in quotations because what I think u mean is “array of pointers-to-array”. Once we get support for that adding structures would simply be a matter of mapping an array index to a name (which if you think about it that’s exactly what C does).

1 Like

That is more then an extra mile. That’s a whole other road.

Yes but i’m thinking struct because is simplest data possible, classes on C++ have some complexibility to memory management etc. Maybe struct with multi dimentional arrays would be amazing.


Also implementing a full scriptable engine like Lua, would be better too :smiley: with VSCode debugging script support but OW devs don't see that :frowning:

Lua is:

  • Simple
  • Faster
  • Light
  • Uses less server resources that current workshop scripts system i believe.
  • Everyone can learn lua because is very, very, very, very, very, easy.

“But dangerous code can attack the server?”

No! Because when you initialize Lua Engine State (the famous lua_State*L) you can specify what are the modules will be available for scripts. And disable some modules.

Also implement a way to debug our scripts with VSCode and lua debugger instead using workshop lagged inspector


I’m trying to create pathfinding for dummy bots, but current workshop script is too limited (specially for multi-dimentional arrays).

1 Like

Mmmmm Lua. I love Lua.

1 Like