Hot answers tagged

98

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 ...


16

A simple way to build a procedural generator is: Randomly build things Run a function that checks whether the output is good If the output is not good, go to step 1 Even if it takes thousands of runs to complete, most simple generators get by just fine with this approach. The advantage is that there's not a lot of smarts required in the generator, and ...


13

You are ONLY generating Perlin noise. This is actually the same as using only one octave, at any frequency. You can base yourself to implent FBM (Fractional Brownian Motion), It is actually what all engines use to make Perlin noise more fractal looking. Bringing it down to code, you can use it like this: //pseudo code function fBm(float x, float y, float z,...


9

Quick note: I don't know lua, however I am fairly good at maths/physics and please bear with me if I cover ideas you are already familiar with. For any object under the force of gravity the horizontal component of the velocity, vx, will remain constant throughout the motion. In this picture the red dots are made at equal times, so the ball travels equal ...


8

Lua is a pretty well developed scripting engine that is flexible and easy to integrate to your games, and is already supported in many game engines, for instance: 2D Agen (Lua; Windows) Blitwizard (Lua; Windows, Linux, Mac) Corona (Lua; Windows, Mac; iOS/Android) EGSL (Pascal/Lua; Windows, Linux, Mac, Haiku) Grail Adventure Game Engine (C++/Lua; Windows, ...


7

Given a restriction of "all areas are at are at least 3-4 blocks wide" the first idea that leaps to my mind is something like the following: pick one of 3x3, 3x4, 4x3 or 4x4 place a block of that size in the center of the grid pick a direction (up, left, right, down) try to place a 3x3 block alongside previously placed blocks in that direction if successful,...


7

You could use pre-generated polyominoes as meta shapes to build an assortment of buildings. Let's say your minimum acceptable distance is 3 blocks. Then the smallest acceptable building unit we'll consider is 3x3. For convenience, I'm going to call that a cell & it gives an area of 9 blocks. Next, take your target starting area & divide it by the ...


6

The method I have used with good results is to give each class that needs Lua bindings a static class method with the following signature: static luabind::scope luaBindings(); The definition of this method looks like this: luabind::scope MyClass::luaBindings() { using namespace luabind; return class_<MyClass>("MyClass") .def(...


5

You really shouldn't use pixel coordinates for game logic. Just use coordinates that are independent of screen size, and make rendering code account for different screen sizes, this way you get much more flexible and maintainable code. So for example assume you are using 1 meter as one unit. Your screen is 2 meters high and 1 meter wide(on every device). ...


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

could block certain functions, but that wouldn't be nice for the modders It's perfectly nice for modders and is basically what everyone does. The only ones you need to restrict are the IO functions, of course, since Lua doesn't really include anything else out of the box. You can instead of "blocking" them replace them with your own versions that do extra ...


5

Alright, found it ! I had to add this to the main.lua file in the editor folder and it worked : package.path = package.path .. ";../?.lua" require "core.engine"


5

In math, the = sign represents the equality comparison operator, an assertion that "the thing on the left has the same value as the thing on the right." This operator is commutative: you can exchange the left & right sides without changing anything (the statement that the left & right sides have the same value remains as true or as false as it was ...


4

LUA would work fine for programming an AI. Here is a basic article over making a FSM in LUA http://lua-users.org/wiki/FiniteStateMachine Here is a basic set of classes to make a desicion tree in LUA http://gamecode4.googlecode.com/svn/trunk/Assets/Scripts/DecisionTreeBrain.lua LUA overall is an extremely powerful language. Any scripting language would ...


4

0) Move your constructor to a separate file, there's no rule that says your entire class has to be all in one physical .cpp file. 1) Put your binding code in a separate function in a different file, have the constructor call it? This would be the preferred method. 2) write your binding code in a separate file, inline, and #include it directly into your ...


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

Sounds like a bug in LuaBridge, so you should report it. As for fixing your project, just remove the const, it doesn't make sense anyway since you're returning a value.


3

Seems like this is a matter of implementing an Entity-Component system? Your "database", or game state, will be incredibly simple: it'll have a container for entities, and that's pretty much it. Each entity will have a unique id, and a container for components. Then, you run the entities through various systems. So constructing the game would involve ...


3

I haven't debugged your code for you, so here are some bits of general advice on how to make things more robust: dirx = -dirx is a problematic way to implement bouncing, because if for whatever reason the ball is already inside an obstacle, or already moving the right direction, it will then be bounced the wrong direction and oscillate back and forth, and ...


3

As Sean Middleditch said in the comments, locals in Lua reference tables, not copy them. Therefore if you have some code like local bullet = create_entity(0, 0, "obj_bullet") bullet.x = 10 -- Commit a change in table what you really need to keep track of is not the local variable bullet, but rather the table returned by create_entity. There can be any ...


3

Fractal noise is usually produced by summing up Perlin noise taken at varying frequencies. You can't really generate it by adding up arrays of white noise... Classic Perlin noise can be found here: http://mrl.nyu.edu/~perlin/noise/ you can then produce "fractal noise" through simple fractional Brownian motion: float fbm(in vec3 v, in int octaves){ ...


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

Yeah, vector geometry really helps when thinking about positions of things. It might be helpful to read over that page for a refresher. To find the vector from your object to the mouse position, subtract the object position from the mouse position: local objectToMouse = { x = mousex - object.x, y = mouseY - object.y } Then you can add some ...


3

This is not exactly an answer - rather a suggestion. A lot of game developers are shifting from LUA (it is slow and it forces you to push data back and forth). For example Star Citizen is using Runtime compiled C++ (actually they use Kythera which runs RCC++). RCC++ lets you script in C++ and reload your modified code on the fly, which - I guess - would ...


3

Directly editing the position of a box2d body will produce non-physical behaviour, it's present because sometimes you will need to teleport bodies to a far away location, or reset the position of an object without the need to destroy/re-create it, etc... In your case the joints are not handling the position adjustments well. The setPosition function should ...


3

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 client-sided functions which you could consider exposing to the scripting engine could just as well be exposed to the server by adding another type of network ...


3

I would generally recommend to avoid making high volume calls into Lua. That is partly about performance but mostly about engine architecture. To get the perf bit out of the way: the bridging code between C++/Lua has overhead compared to just calling Lua from Lua or calling C++ from C++. Of course, even good Lua itself is significantly slower than decent C++...


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