Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Sun Nov 19, 2017 5:36 pm

All times are UTC




Post new topic  Reply to topic  [ 19 posts ] 
Author Message
 Post subject: Lua?
PostPosted: Mon Mar 19, 2007 4:08 pm 
Offline
Transport Empire Moderator
Transport Empire Moderator
User avatar

Joined: Fri Jan 10, 2003 12:21 pm
Posts: 2125
Location: Wroclaw, Poland / Katowice, Poland
Or another scripting language.

Methinks there was (wise) decision to configure the game with LUA scripts. So - anyone have seen some sort of a tutorial howto use LUA? I have never used it, so I dunno how it works really.

_________________
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.


Top
   
 Post subject:
PostPosted: Mon Mar 19, 2007 4:20 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Tue Dec 03, 2002 10:36 am
Posts: 13161
Location: The Netherlands
SimCity4 uses LUA scripts extensively and the game also has a large mod community. Perhaps you can find any help there?

_________________
Image
Dutch Trainset for OpenTTD | Dutch Trainset Topic | Combined Roadset v0.10


Top
   
 Post subject:
PostPosted: Mon Mar 19, 2007 6:58 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Sat Nov 30, 2002 5:10 pm
Posts: 6939
Is a scripting language really useful for an open-source game? We don't have to mod it.


Top
   
 Post subject:
PostPosted: Mon Mar 19, 2007 7:04 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Tue Dec 03, 2002 10:36 am
Posts: 13161
Location: The Netherlands
A scripting language isn't just for modding. In SimCity4, LUA scripts determin which route citizens take to get to their work i.e..

_________________
Image
Dutch Trainset for OpenTTD | Dutch Trainset Topic | Combined Roadset v0.10


Top
   
 Post subject:
PostPosted: Mon Mar 19, 2007 10:32 pm 
Offline
OpenTTD Developer
OpenTTD Developer
User avatar

Joined: Mon Jun 09, 2003 6:21 pm
Posts: 4532
Location: /home/sweden
I've used embeded LUA in Junctioneer before, but for me it took to much time to maintain in a one-man hobby project. I think the LUA-homepage is a good start.

The versions of Junctioneer that uses LUA (can be found at sourceforge) are known to be broken on newer GCC-versions. >= 3.4 at least, maybe even older. 8)


Currently OpenTTD are working on using Squirrel (choosed because it looks similar to C++) for AI-scripts. I've not looked into the internals of that though.


Top
   
 Post subject: Re: LUA?
PostPosted: Sat Nov 15, 2008 10:01 pm 
Offline
Engineer
Engineer
User avatar

Joined: Mon Jan 07, 2008 10:25 pm
Posts: 43
Location: Borger, the Netherlands
You could also ask Monte Cristo, (they're working on CitiesXL), (www.citiesxl.com)

They are using LUA scripts for pathfinding.

_________________
Stop those stupid shooting games, make peaceful games!


Top
   
 Post subject: Re: LUA?
PostPosted: Sat Jan 03, 2009 8:21 pm 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
Hey.

I somehow missed this topic, so sorry I didn't post earlier.

I know Lua quite well and I think it would be great for it to be Transport Empires's scripting language. I'm not for creating some home-brewn solution, because it can hardly be better than lua and it would mean a lot of additional effort.

Lua is small and fast scripting languale written in C. It was built for embedding into C applications and it does it's job great.

Here are the Lua's features:
- It's implements a state machine (object) which keeps the context until deleted. So, you can perform many separate operations with it in all possible means. This includes parsing files or C string as code or any operations described below.
- You can read and write values to the lua's enviroment
- You can register C functions with lua and then call them from within the script. The functions must use lua api to get arguments and return values, but othervise they are ordinary C functions.
- You can call lua functions from outside, using the api. This includes passing arguments and reading results. Could be good for callbacks. The functions to use this way are fully regular lua functions, no tricks.
- You can export C pointers into lua as 'light userdata' variables. Such pointers become regular lua variables. Then, you can pass it into C functions of your choice to manipulate it. Lua can't go directly into a C object's attributes, but you can create access functions. Also, lua objects are hash tables and anything can serve as index, so you can easily bind lua data to c objects.
- You can also allocate an object with lua api. Such object becomes 'full userdata' variable inside lua. The benefit is that such object can have lua functions attached as methods. Also, such object is garbage-collected by lua, unlike light userdata, where the pointer is programmer's responsibility.
- You can load dynamic libs (.dll and .so) as lua modules. I don't know this in detail, only that it works. The api of such module must be made with lua-ready functions.

I hope I didn't miss anything. I'd really like to see lua with TE.

Now, it's quite easy to learn the language itself, there are lots of good resources:
http://www.lua.org/pil/ Programming in Lua online book
http://lua-users.org/wiki/TutorialDirectory Detailed tutorials about every aspect of the language. The whole site is very useful.
http://www.lua.org/manual/5.1/ Manual. Not good for learning, but good reference.

Unfortunately, using lua with C is documented quite poorly. I learned mostly from the reference manual. I also found some article on gamedev, but it's not there anymore. I can't provide any materials right now, you'll have to search. But, knowing this, I created a demo showing all the features I wrote about. There are both source and binary, the lua lib is bundled.

Edit: I forgot, there is a simple game engine which is built to run lua scripts, http://www.love2d.org/. It's a great demo how lua can work in action and also how fast it is. There are some games on the forums http://love2d.org/forum/, so grab one and check it out!

Edit2: Just found out that ogre's built-in gui system, CEGui, has a Lua binding! Check out this tutorial http://www.cegui.org.uk/wiki/index.php/Getting_Started_with_Lua_and_CEGUI. It's dated 2005, so I'm sure the thing is in working state today. With the TE game facilities being exported or implemented in Lua, you could actually create the whole Gui, including the tools, with just lua.

I hope to hear TE will use Lua :))


Attachments:
lua_demo.zip [418.53 KiB]
Downloaded 206 times

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!
Top
   
 Post subject: Re: LUA?
PostPosted: Tue Jan 06, 2009 11:12 am 
Offline
Transport Empire Moderator
Transport Empire Moderator
User avatar

Joined: Fri Jan 10, 2003 12:21 pm
Posts: 2125
Location: Wroclaw, Poland / Katowice, Poland
What would you need, in terms of an interface, to build a workable gui, including widgets?

_________________
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.


Top
   
 Post subject: Re: LUA?
PostPosted: Tue Jan 06, 2009 1:14 pm 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
uzurpator wrote:
What would you need, in terms of an interface, to build a workable gui, including widgets?


The gui creation and manipulation Lua functions are part of CEGUI, so I only need Lua functions which work with the engine:

An API which gives me engine-relevant input, for example: which tile the cursor is hovering, what object (vehicle, building, vegetation, whatever) does it point at, what's the camera position and angle and what area is actively visible (to display the map) and so on...

The second thing are functions that actualy do something useful in the engine. Like: plant a tree, lay track from here to there, terraform this edge/tile/area, stop/run vehicle, move/rotate/zoom the camera, you get the point.

For example, a tree-planting gui would need this:

A function returning the mouse-pointed tile coordinates. Could look like:
Code:
tileX, tileY = te.mouse.getPointedTileCoords()

Note that Lua functions can return multiple values.

A function giving additional positioning information. From the screenshots it appears that a tile has 4 quadrants, each for one tree. So, I need a function telling me which quadrant the mouse is pointing. Like:
Code:
quadrant = te.mouse.getPointedTileQuadrant()


And finally, a function that actually plants a tree in the chosen position
'tree' is the tree identifier
Code:
te.terrain.plantTree(tree, tileX, tileY, quadrant)


With this equipment, I can create any form of tree-planting tool like: single-tree planting, full-tile planting, area planting with one/x/random-amount tree(s) per tile, whatever... All in Lua.

I haven't seen cegui's docs yet, but I work with love engine a lot, so I know how lua-bound things work.

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!


Top
   
 Post subject: Re: LUA?
PostPosted: Tue Jan 06, 2009 1:48 pm 
Offline
Tycoon
Tycoon

Joined: Fri Jun 08, 2007 8:00 am
Posts: 1656
Just because it hurts my eyes I'll stress that it's Lua (like anoobis posted) not LUA. :)

And I'm fairly familiar with Lua for I've scripted some things for MTA (which uses CEGUI too btw)
Imo lua is just so easy language to learn and there are lots of people who know lua, so it wouldn't be such a hurdle to make scripts for it as it is with learning nfo etc. If just an API is convinient enough

_________________
PS: And I stopped the propaganda to support Dave Worley since he got a nice new red hat now.[/color]
I know I have a BBCode error in my signature but I really cba to fix it.


Top
   
 Post subject: Re: LUA?
PostPosted: Fri Jan 09, 2009 12:09 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Aug 09, 2004 12:14 am
Posts: 1293
Location: Gouda, The Netherlands
LUA is quite mature, but what are the arguments to use LUA, instead of LISP, squirel, XML (to name but a few), something else or even something homegrown? Isn't it better to design/find a language which suits the needs of the game, instead of focusing on the needs of the user (this doesn't mean you should go with NFO or assembler)?

imho as much as possible should be able to be transferred from the config file to the game engine, without much need for the script interpreter. Humans should be able to read and understand such a language.

Now, how far can you go with LUA before you actually need to constantly interpret the the script in order to use the entities depending on those scripts? How far can you go with the other languages?

And most importantly (and the reason why I ask these questions) what's the performance hit of LUA and all its competitors?


Top
   
 Post subject: Re: LUA?
PostPosted: Fri Jan 09, 2009 10:34 am 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
Expresso wrote:
...XML...

I think there's a little misunderstanding. There is much more to a scripting enviroment than just parsing config scripts, you can actually implement the game logic in it. That leaves XML out.

Expresso wrote:
...something else or even something homegrown? Isn't it better to design/find a language which suits the needs of the game...

A basic need of every game is to be ever finished, and trying to create a homebrewn scripting would slow the process down. Not to mention there is a small chance of coming up with something new - such an effort would likely re-implement some already existing enviroment (and that enviroment would quite probably be Lua again).
CEGUI has built-in Lua scripting support. As I said above, this allows implementing gui interactions fully in Lua. Using anything else would break the concept.

Expresso wrote:
imho as much as possible should be able to be transferred from the config file to the game engine, without much need for the script interpreter. Humans should be able to read and understand such a language.

Lua object notation is similar to javascript's JSON notation which is readable well enough. And, you can implement your own config-file parser in Lua.

Expresso wrote:
Now, how far can you go with LUA before you actually need to constantly interpret the the script in order to use the entities depending on those scripts? How far can you go with the other languages?

There is no possible reason for static interpretion of Lua scripts. Read my first post carefully - Lua offers enough features to manipulate the entities, and if i missed something, please name the case.

Expresso wrote:
And most importantly (and the reason why I ask these questions) what's the performance hit of LUA and all its competitors?

I haven't checked any performance tests, but frankly, I don't care. I know Lua is fast enough, it's built for the purpose of embedding into C programs and since it's so widely accepted, I think we could hardly beat it. For me, the features Lua offers are the most important thing.
And not least of all, I know Lua and if it's used, I can help. Otherwise not.

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!


Top
   
 Post subject: Re: LUA?
PostPosted: Sat Jan 10, 2009 12:57 am 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Aug 09, 2004 12:14 am
Posts: 1293
Location: Gouda, The Netherlands
An00biS wrote:
Expresso wrote:
Now, how far can you go with LUA before you actually need to constantly interpret the the script in order to use the entities depending on those scripts? How far can you go with the other languages?
There is no possible reason for static interpretion of Lua scripts.
Yes, there is. You don't want to figure out again and again what the specs are of some entity, simply to display it or alter its state - that would hammer performance down quite a bit. Script calls should be reduced to a minimum, and I wonder whether and to what extent Lua offers support for that.
An00bis wrote:
Expresso wrote:
And most importantly (and the reason why I ask these questions) what's the performance hit of LUA and all its competitors?

I haven't checked any performance tests, but frankly, I don't care. I know Lua is fast enough, it's built for the purpose of embedding into C programs and since it's so widely accepted, I think we could hardly beat it. For me, the features Lua offers are the most important thing.
Fast enough might just translate in a gigantic performance hit if too many scripts need to be run each second.

A nice and clean way to do that could be to have multiple entry functions (one for defining static information and the other for entity specific code which simply can't be expressed in a simple bunch of constant values). This could drasticly decrease the calls to the scripting engine. Another solution (less clean: involves more files) could be to have a file for all static information which tells the engine which files to use for what type of call (construction, query (from the engine), whatever).

Does Lua support a mechanism like that (one way or the other)?
If yes, I see no further objections (might even go of and pick it up ;) ).
If no, how do you intend to get over the performance hit all the scripts provide on a large map?

EDIT: I'm looking at the language now, and the tables seem a quite interesting option to solve the static data problem :] .


Top
   
 Post subject: Re: LUA?
PostPosted: Sat Jan 10, 2009 10:50 am 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
Expresso wrote:
EDIT: I'm looking at the language now, and the tables seem a quite interesting option to solve the static data problem :] .

Good. :)) Go on.

Actually, I think we're getting into little too much detail here. The thing is, I don't really know how TE will make use of Lua, if even. I suggest one way, which would provide great flexibility, but would make quite extensive use of the scripts. And while I know Lua is fast enough to fully implement simple games (see http://www.love2d.org/), I can only anticipate what it'll do with TE.

Expresso wrote:
An00biS wrote:
Expresso wrote:
Now, how far can you go with LUA before you actually need to constantly interpret the the script in order to use the entities depending on those scripts? How far can you go with the other languages?
There is no possible reason for static interpretion of Lua scripts.
Yes, there is. You don't want to figure out again and again what the specs are of some entity, simply to display it or alter its state - that would hammer performance down quite a bit. Script calls should be reduced to a minimum, and I wonder whether and to what extent Lua offers support for that.

What exactly is an entity in your sense? In mine, it's a Lua object (data type 'table') which resides inside the Lua enviroment (lua_State object). Acessing it from scripts is straight-forward, and accessing it from 'outside' is no problem either, check the demo I attached to my first post.

Expresso wrote:
...how do you intend to get over the performance hit all the scripts provide on a large map?

Really, I'm going to wait and see.

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!


Top
   
 Post subject: Re: LUA?
PostPosted: Sat Jan 10, 2009 2:13 pm 
Offline
Tycoon
Tycoon
User avatar

Joined: Mon Aug 09, 2004 12:14 am
Posts: 1293
Location: Gouda, The Netherlands
An00biS wrote:
Expresso wrote:
Yes, there is. You don't want to figure out again and again what the specs are of some entity, simply to display it or alter its state - that would hammer performance down quite a bit. Script calls should be reduced to a minimum, and I wonder whether and to what extent Lua offers support for that.
What exactly is an entity in your sense? In mine, it's a Lua object (data type 'table') which resides inside the Lua enviroment (lua_State object). Acessing it from scripts is straight-forward, and accessing it from 'outside' is no problem either, check the demo I attached to my first post.
Refer to this thread, that's what I mean with an entity. Information which is going to be needed constantly by the engine, shouldn't reside inside a script. This does not imply that that information can't be delivered or manipulated by a script, that a script can't be used to resolve exceptions or too dynamic situations. But it does mean scripting should be avoided there where it would hamper performance too much.

An00bis wrote:
Expresso wrote:
...how do you intend to get over the performance hit all the scripts provide on a large map?

Really, I'm going to wait and see.
And that's exactly what I'm worried about. Solving problems the moment they present themselves is a good way to create even bigger problems later on.


Top
   
 Post subject: Re: LUA?
PostPosted: Sat Jan 10, 2009 3:13 pm 
Offline
Engineer
Engineer
User avatar

Joined: Mon Aug 27, 2007 6:46 pm
Posts: 97
Location: mapy.cz/?query=rajhrad
Expresso wrote:
Information which is going to be needed constantly by the engine, shouldn't reside inside a script.

Of course not. For these situations, you just implement the entity in C and manipulate it with Lua. Or, if that's not adequate either, you only use Lua to setup it. Whatever.

Expresso wrote:
... scripting should be avoided there where it would hamper performance too much.

You finally get to the point - it's not the technology, it's the way you use it.

Expresso wrote:
Refer to this thread, that's what I mean with an entity.

This thread made me little worried. Creating homebrewn config file parsers and entity managers is definitely inventing the invented. The post is actually just an announcement, there is no code in the SVN which would give me better picture. But from the example conf file I suggest Uzurpator's going to pre-code entities as C++ objects, code various interactions among them and then control it all by the values from the config files. It reminds me of my own suggestions, back then before I learned Lua, which completely changed my view of game setup. I guess uzurpator doesn't know game scripting either, othervise he'd be thinking differently. So, that's the main reason I'm trying to push Lua into the project.

_________________
[Update Aug 2013] FlexRails track buiding demo coming soon!


Top
   
 Post subject: Re: LUA?
PostPosted: Thu Jan 22, 2009 3:40 pm 
Offline
Transport Empire Moderator
Transport Empire Moderator
User avatar

Joined: Fri Jan 10, 2003 12:21 pm
Posts: 2125
Location: Wroclaw, Poland / Katowice, Poland
Anoobis:

The reason I am using this approach beacuse:

1. I know this approach, unlike Lua, of which I have little knowing.
2. for A LOT of tasks in a huge game Lua is too slow (lua is around 10-15 times slower then raw C++).

However, for A LOT of auxiliaries like aforementioned parser, some scripting language is essential, even if only because C++ is an ass at text processing.

Which is the reason I am here. If I provide an interface, can you code an asset manager entity in Lua? This object would parse configs (if you have better proposition for input format, please state it) and expose data needed to config the game.

If you are interested -> PM.

_________________
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.


Top
   
 Post subject: Re: Lua?
PostPosted: Mon Jan 26, 2009 5:21 pm 
Offline
Engineer
Engineer
User avatar

Joined: Mon Jan 07, 2008 10:25 pm
Posts: 43
Location: Borger, the Netherlands
I just found out that Simcity 4 is also using LUA.

While editing and replacing some textures i found a LUA script file in one of their .DAT files. And as i'm a huge fan of Simcity 4 and played thousands of hours i must say, YES use LUA! Maybe LUA is slow on large programs but SC4 is large.. and it works fine!

_________________
Stop those stupid shooting games, make peaceful games!


Top
   
 Post subject: Re: Lua?
PostPosted: Tue Aug 17, 2010 10:28 am 
Offline
Traffic Manager
Traffic Manager
User avatar

Joined: Tue Dec 21, 2004 5:35 am
Posts: 185
Skype: andrey-zaharov
Location: St. Petersburg, Russia
For sure Lua as language for configs, describing GUI
and for scripting behaviours (economic)

_________________
OpenTTD Hard Game Pack


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 19 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000-2017 phpBB Limited

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2017.
Hosted by Zernebok Hosting.