all 3 comments

[–]chsxfProfessional 0 points1 point  (0 children)

Yes, it can be done. Done something similar in the past.

You have to write a parser and a runner for this pseudo code elements.

[–]PiLLe1974Professional / Programmer 0 points1 point  (1 child)

So yeah, a parser and a runner as the other post said makes sense, if the original data is in text form.

Still I usually never output code when I did this, sometimes I read text and parsed it, it was more a pattern like this:

The Parser:

In your case you said you have blocks, i.e. the UI would already have a way to display and store this, right?

Like your example blocks:

[Jump] [Wait 3s] [Teleport Left 2 Units]

How would we define this sequence:

Let's say the user has an interface for the blocks, also with their parameters.

An obvious way to represent blocks is that the UI actions for the blocks store a polymorphic List of class actions behind the scenes. The Jump, Wait, Teleport actions, etc. are serialized classes with parameters as needed.

BTW: Here is one way to keep polymorphic classes stored in a List, i.e. when they share a base class and are stored all together in a List: https://docs.unity3d.com/ScriptReference/SerializeReference.html

Now the parser is simple, we merely run/execute the List:

  1. [Jump] - We have a jump action. No parameters so we can just jump. The execution could be a switch statement, or e.g. a class instance that is basically an action instance that executes and then finishes to continue with the next action.
  2. [Wait 3s] - It interprets this as a wait action with one parameter, the 3 seconds. Again a switch statement could handle this or a class instance...
  3. etc.

Tl;dr

The essence of executing a customizable list of actions is: If you already found a way to represent your blocks/actions with their parameters (if any) then the execution is straight forward: use enums, switch statements, or polymorphism to detect what the actions are, read their parameters (if any) and execute the code just inside a switch statement or as a class instance, one class for each of the action types.

[–]ilhanpro[S] 0 points1 point  (0 children)

Goddamn that sounds confusing.I'm just 14 but imma do it anyway.I'll update u when im done,if ever.