Programming inside a game?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Programming inside a game?

Post by xNick1 »

I recently played else heart.break(), a unity game where you can program inside the game in a fictional programming language interpreted by the game.
One can "hack" the game.
You can do stuff like opening closed doors by writing code which tries every combination and so on.
How would someone start to make such a thing in a game?
What are the precautions you have to apply to make sure you don't execute that code in the "main" game?
I mean, you need a sand box or something.
Has someone ever tried to do that?
Do you know any other games like that?
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Programming inside a game?

Post by ivan »

Lua's pcall can evaluate any string into a function.
But if you want your game to execute a 'custom' language then you're looking at compiler theory.
The basic principle is: you start with an input string, break it into tokens (lexical analysis) and associate the tokens into some sort of (tree-like) structure.
The old King's Quest games are based on the same principle, except that the 'language' used there has the simple grammar: verb-noun (go north, pickup object, etc)
Last edited by ivan on Mon Jan 16, 2017 7:25 am, edited 1 time in total.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Programming inside a game?

Post by raidho36 »

Take a look at Bussard project.
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Programming inside a game?

Post by Germanunkol »

I recommend using Lua (or a simplified version of it) for this purpose. This way you don't have to write your own compiler.
You can start by looking at Lua's loadstring function. You can pass it code as a string (which the user has typed) and it will get interpreted. Then you can run that chunk of code.
I did something similar in trAInsported - players write Lua code and then the game interprets it and lets the trains act accordingly. You can check out the sourcecode for it if you want to - I do a lot of sandboxing - but it's a little old and messy.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

Re: Programming inside a game?

Post by Positive07 »

Yes, trAInsported and Bussard are definetely stuff to check, also I suggest you look at Sandbox a library by Kikito.

There is also LIKO12 which allows you to code entire games, and sandmas which allows you to modify your LÖVE game at runtime

Someone reacently asked something similar and I gave a similar answer

Making you own programming language is hard (not impossible), it will take lots of time, in addition you will need to write documentation, modules and what not, you'll end up coding a new language but never coding your game, so be careful with that. I haven't even talked about programming a code editor in LÖVE which doesn't provide any form of textinput element... that would take time too so I recommend Pollywell which is what Bussard uses
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 49 guests