97 votes
Accepted

How does Lua work as a scripting language in games?

Scripting is a programming abstraction in which you (conceptually) have a program (the script) running inside another program (the host). In most cases, the language in which you write the script is ...
user avatar
  • 13.2k
42 votes
Accepted

What's the technology that allows programming inside a game?

Scripts written in scripting / embedded / interpreted languages such as "Lua", "Lisp" or "AngelScript" (more here) can be updated during the game [*] and then are interpreted (= executed) on the fly. ...
user avatar
12 votes
Accepted

What can I do to avoid one-off flags and checks throughout my code?

Have you looked into entity component systems and event messaging strategies? Status effects should be components of some sort which can apply their persistent effects in an OnCreate() method, expire ...
user avatar
  • 454
12 votes

What's the technology that allows programming inside a game?

Embedded language is the proper technical term. In practice, languages which are used inside other applications (such as games) are often referred to as scripting or even interpreted languages, ...
user avatar
  • 395
11 votes

What can I do to avoid one-off flags and checks throughout my code?

RobStone is on the right track, but I wanted to elaborate since this is exactly what I did when I wrote Dungeon Ho!, a Roguelike that had a very complex effects system for weapons and spells. Each ...
user avatar
11 votes

What's the technology that allows programming inside a game?

You are looking for a way to change the code into some actions. This is precisely what interpreters are doing. Take a look at Python. You run it, and bam! You land in REPL(Read Eval Print Loop). You ...
user avatar
7 votes
Accepted

Is it possible to mod a game to use a scripting language like Lua?

It depends on what kind of modding the game allows. When the game in question already includes a sufficiently powerful script interpreter, one could write a transcompiler which takes a script written ...
user avatar
  • 112k
6 votes
Accepted

How do engines that can be scripted with a different language than the engine code work?

There are many ways to implementing scripting in game engines, or applications in general. Most conventional scripting languages are just like any other library. Just as libpng interprets a ...
user avatar
5 votes
Accepted

NPC daily routines and scene loading

Don't hard-code it, or it'll indeed end up very messy. You need to script the NPCs daily routines into some data file (XML or other). Something along the lines of: ...
user avatar
5 votes

How does Lua work as a scripting language in games?

Scripting languages like Lua can be used in several ways. As you said you can use Lua to call functions in the main program but you can also just have Lua functions called from the C++ side if you ...
user avatar
5 votes

How to send an interface message?

Method 1 - Unity UI Event System Thanks to Byte56 for pointing out that there's a new approach to messaging in Unity, which is much more similar to what the asker describes in Unreal. One quick ...
user avatar
  • 114k
5 votes
Accepted

What is the class name in Unity's AddComponent?

It's the class name of the component you want to add. For example, if you created a MonoBehaviour script named GoToPosition and wanted to add it to a game object ...
user avatar
  • 72.7k
5 votes

In GameMaker, is it possible for users to code something into a game while playing, and verify that it is correct?

What you're describing is effectively running gameplay mechanics in a virtual machine, which can simplify the process of authoring them and insulate against bad behaviour. As it happens, a lot of ...
user avatar
  • 114k
5 votes
Accepted

Array but with a name for every element (value)

There are multiple methods to deal with this. 1) You could create an enum with custom values that you could refer to: ...
user avatar
  • 271
4 votes

How does Lua work as a scripting language in games?

Since no one mentioned this, I will add it here for those interested. There is a whole book on the subject called Game Scripting Mastery. This is a fantastic text that was written quite a while ago, ...
user avatar
  • 696
4 votes

Is it safe StringToHash() to use in Unity?

Assuming that the hash function used by StringToHash doesn't have serious bias, the chance of two hashes being alike is one in 4 billion. When you generate a lot of hashes, the chance of a collision ...
user avatar
  • 112k
4 votes
Accepted

Can you write the current frame number to a text file?

You can retrieve the number of frames that have passed with Time.frameCount();, if that's what you're looking for. http://docs.unity3d.com/ScriptReference/Time-...
user avatar
4 votes
Accepted

Unity3D: 'Physics' does not contain a definition for 'Raycast'

I'd guess you made your own class or imported some other class named Physics. Try fully qualifying it UnityEngine.Physics.Raycast...
user avatar
  • 72.7k
4 votes

How to make Unity game moddable with scripting in a friendly way?

A somewhat blunt approach would be to let modders write C# code and then have your game read & compile those scripts, using them as though they were code the game was built with. This has some ...
user avatar
  • 114k
4 votes
Accepted

Event Trigger for sprite not working

I see that the backward image is turned around 180 degrees to make it face opposite the direction of the forward image. This means that its front side is facing away from the camera. By default, this ...
user avatar
  • 1,351
4 votes

Is allowing the server to remotely execute code on a client a security risk?

You might want to ask yourself if you really need client-sided scripting at all. You might be able to make many interesting mods possible by simply making your network protocol powerful enough. Most ...
user avatar
  • 112k
4 votes

An object reference is required to access non-static member

Your nextLevelName member variable is not static, meaning there could be a different name set on each instance of the ...
user avatar
  • 114k
3 votes

How does Lua work as a scripting language in games?

Most scripting languages, including Lua, operate on a Virtual Machine (VM), which is basically a system to map a script instruction to a "real" CPU instruction or function call. The Lua VM normally ...
user avatar
  • 3,027
3 votes

Player in Spaceship

Each rigid body has an attribute indicating if it's affected by gravity or not. You can just mark that attribute as true, whenever player enters the spaceship, and later turn it false, when he exits. ...
user avatar
  • 8,667
3 votes

"Binding" script functions to C++ functions

There is no one way to bind an engine with a scripting language, nor is there really an easy way or a best way, it's all very dependent on your architecture, scope and ambitions, I can think of two ...
user avatar
  • 601
3 votes

iOS build size is too large in Unity

There is a unity guide for general optimisation on the unity website. To summarize it quickly (read the article): Reduce texture sizes (You can have specific settings Just for IOS) Compress meshes ...
user avatar
  • 3,516
3 votes
Accepted

How can I get the assignment of an object back?

You are creating a tower prefab with Instantiate (towerPrefab, transform.position, Quaternion.identity);, but you don't do anything with the GameObject it returns. ...
user avatar
  • 112k

Only top scored, non community-wiki answers of a minimum length are eligible