Click here to Skip to main content
15,031,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to build a game engine written by c++ and use C++ in the scripts.
anyway i want to execute a compiled script but how?

how do game engines that use "compiled code" execute compiled script?
do they compile scripts as DLL then call them or what???


What I have tried:

i made my game engine 10 times and i failed because i don't know how it's work
i have read a book called "Game Engine Architecture" i learned much information
but i still can't make a game engine
Updated 17-Oct-20 6:48am
Richard MacCutchan 17-Oct-20 11:41am
A game engine is a huge project. It may use compiled code in dlls, or compile it on the fly. But this forum is not really the place to help as it deals in specific technical questions.

Actually you have two rather complex problems here. One is executing script code and the other is writing a game engine. I recommend tackling them separately.

Many game engines use script languages for game play logic but very, very few use c++ as the language. I can't think of any off-hand. Most use one of the common scripting languages because facilities for embedding them within applications are rather common. Some use proprietary c-like languages because there are lots of parser libraries for it that can be adapted. Usually scripted code for games is executed interpretively so it is not compiled to machine code. If you don't understand the difference then you have a lot to learn and a lot of reading ahead of you.

If by "compiled code" you mean secondary code compiled into libraries, yes, that is possible but not how games are usually built. A generic game engine is usually used but the engine is in a library and the game itself is the application. This is how most games are built. When games use scripts they are usually loaded at run-time and compiled on the fly to a sequence of "byte code" that can be executed efficiently by an interpreter. This isn't as efficient as machine code but it usually doesn't have to be. Gameplay logic is called when events occur like when a user presses or clicks a button so they don't occur constantly and the code that services the event does not have to be ultra high performance.

I hope this gives you a taste of what is involved. You might want to start by reading up on the two engines you listed in the tags. They use different script engines. Unity uses .net languages like c# and I am not sure what Unreal uses now. It used to be a c-like language and still might be but I don't know for certain.

To wrap this all up, you should know how a game engine works since you read that book. The next thing to investigate is how script engines work and how they are embedded within applications. Then look into how game engines embed script languages. It is a bit more specialized than how standard applications do it.

Most importantly, don't expect everything to be spelled out for you in a website forum post. There are lots and lots books written on solely on these two subjects. A forum post can only hope to barely scratch the surface of the topics.
That's a little tiny question, but ... so is "why are rainbows?". The answer to that one is horribly complicated, far far too much for a little text box like this - and so is the answer to yours!

As Rishard has said, writing a game engine is a lot of work - it's normally a project for a large team of experienced developers, not for a single coder, and to be honest I wouldn't even attempt it myself (and I've been in this game for decades!)

If you really think you want to write your own, then start here: how to write a game engine - Google Search[^] and follow a couple of links. They will at least give you a sense of the scale you are looking at, and the subjects you are going to need to learn to get started.

If you decide to continue, you have an interesting project here - but it's going to take you a long time to get "usable results" so try not to get disheartened.
Good luck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900