Running user-created scripts problems | How to create When The Farmer Was Replaced

Goal: What I want is to create a game where the player can write Lua scripts to control/move robots. The gameplay would be very similar to an existing game called ‘When The Farmer Was Replaced’.

Problem: The problem is that if the player wrote an infinite loop, wouldn’t it freeze the game?

I’ve done an AI-assisted research, and it offer these solutions:

  • Creating a new separate process for user scripts.
  • Using Lua coroutines.
  • Using Lua sethooks.
  • Using a game engine that supports multithreading.
2 Likes

JS have workers and that makes it whole lotta easier. I think I’d use JS game engine for now.

You would most likely execute one step of the program, save the state and program counter, then yield back to the engine, and next frame you restore state and program counter and execute the next instruction.

Yes, this is perfectly suited for this.

I’ll leave this here for you. A robot programming game made with Defold:

1 Like

It seems like my knowledge on Lua is the bottleneck of truly understanding the problem.

I appreciate it a lot. I really want to learn Defold and use it for my thesis, thanks for being supportive :slight_smile:

2 Likes