97

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 different from the language in which the host is written, but any program-inside-a-program abstraction could be considered scripting. Conceptually, the common ...


41

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. You can bind elements from those scripts to your native compiled coding (C++, etc.) so that the scripts can then execute logic from your application. E. g. a ...


12

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 their effects in OnRemoved() and subscribe to game event messages to apply effects which occur as a reaction to something happening. If the effect is ...


12

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, although they should not necessarily be interpreted or used for automating routine tasks. Googling "scripting languages for games" would probably yield more useful ...


11

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 card should have a set of effects attached to it, defined in such a way that it can indicate what the effect is, what it targets, how, and for how long. For ...


11

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 define a function "hello" which prints "Hello, world". And there you have it! Notice that you didn't compile anything; interpreter did some magic to create ...


7

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 in Lua and transforms it into a program in the scripting language of the game so that it can be executed. Alternatively, one could even create a Lua ...


6

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 particular data format and provides APIs to read the results of processing that format, a scripting language library like Lua read in a particular format (Lua source ...


5

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 want. Generally you build up an interface to allow some flexibility with the scripting language of your choice so you can use the scripting language in a series of ...


5

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: <npc name="george"> <schedule start="0:00" end="8:00"> <sleep at="home"/> </schedule> <schedule start="8:00" end="9:00"> <walk leave="home" ...


5

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 heads-up: This approach is quite verbose compared to what I'm used to. If you just need a quick way to call a method on another object, without all the ...


5

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 via script you would call: AddComponent("GoToPosition"); That being said, this isn't typically a method I use. I'd rather be explicit about it and use the alternate method of adding components: ...


5

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 games already do their gameplay like this under the hood! If you've ever heard developers talk about incorporating scripting languages like Lua, or node graph ...


5

There are multiple methods to deal with this. 1) You could create an enum with custom values that you could refer to: public enum Grenades { Standard = 5, Cluster = 10, } You can then refer to it by int value = Grenades.Standard 2) You could use a dictionary to store values: Dictionary<string, int> grenades= new Dictionary<string, int>(); ...


4

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 gets larger than one would expect (see birthday problem), but when you have 100 different strings, the overall chance of a collision is still at about a million ...


4

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, but it remains completely relevant today. This book will not only show you how scripting languages fits into native code, it also teaches you how to implement ...


4

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-frameCount.html From there, writing to a file in C# is pretty trivial: http://forum.unity3d.com/threads/how-to-write-a-file.8864/


4

I'd guess you made your own class or imported some other class named Physics. Try fully qualifying it UnityEngine.Physics.Raycast. Alternatively, you can make sure you make a clean build to ensure there's nothing left over that's messing up your build.


4

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 advantages: Modders can use the existing Unity API, so it's already familiar to many, with extensive documentation and tutorials. It's very fast to get up and ...


4

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 will cause the event system to ignore it. There are three easy fixes for this. 1. Make a copy of the arrow texture and use your image editor to reverse it. Use ...


4

Your nextLevelName member variable is not static, meaning there could be a different name set on each instance of the enemiesCount class, of which you could have dozens or thousands if you wanted. The DecreaseCount method, on the other hand, is static, meaning it's shared across the whole enemiesCount type and not attached to any one instance. That means ...


3

I would look heavily into state machines and deserializing the XML data into state instances. You can create class definition for a condition, be that an integer on an item for it's int brightness = 4; value or a string name = "torch"; in the inventory. Something along these lines: public enum ConditionType{ default, itemLevelReq, itemEquip, ...


3

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 runs in the same process as the main application. This is specially true for games that use it. The Lua API provides you with several functions that you call in ...


3

Using an existing scripting language like Lua may be overkill for your needs, but on the other hand it also actually solves your needs with a minimal amount of effort wasted reimplementing the wheel. I would reconsider its use. Especially as a scripting language of this type can come handy in plenty of other places. If you really just don't want to use Lua,...


3

There's a few routes that you can take. Some include making an event type system where actions in your C++ code map to functions directly/indirectly in your scripting system. So, if you read that a player presses the up key in game, that will send an event to the scripting system that will then decide what to do. You could also hard code certain actions and ...


3

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. But that'll limit you with a big limitation. The gravity itself in unity is something global, meaning all entities are affected by same gravity force (if any). ...


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