Public Group

# Scripting and C++

This topic is 3650 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I don't think I'm really to a point where I want to dive into this yet, but am just curious. Using an Interpreted language (Lua, Python, etc.) in your C++. What are some advantages to it? I understand when programs get bigger, it can save compilation time when prototyping stuff (not having to recompile when you change your stuff written in Python)....but surely that's not ALL it's for. What other uses are there? Also are there any pro's or cons to Lua and then pros and cons to Python. If I ever start messing with it I will probably use python, since I am familiar with it. I believe I've found tutorials on how to implement both, but just curious as to some of you guys uses for it, or/and if it is something I will need/should learn. I probably will just for fun regardless though.

##### Share on other sites
The main benefit is that almost any language that isn't C++ is an easier language to work with [grin]. Scripting languages tend to use garbage collection, which reduces the amount of work on the programmer. In addition, they tend to be more expressive with less code than the same thing written in C++.

Don't underestimate the productivity bonus you get when you take the compile cycle out of game logic development.

##### Share on other sites
Write pong in C++ then write it in Python. Now count up how many pages long each is and how long each took to write. That should show you why Python would be desirable to have as an option as opposed to C++. It's about speed, ease of use and productivity.

~Cody

##### Share on other sites
Besides the usual reasons that most people give, scripting languages help insulate the rest of the team from the changes made by one designer or artist.

For instance, if a designer is scripting a level, and makes errors in the script, this will not break the entire game, which is what would happen if the level gameplay was doing in code.

If an artist is coming with a shader for an asset, and makes a mistake, again, this will not break the game.

Having a scripting language is one of the ways you can ensure your game remains in a playable state.

Hope that helps,
Brian

##### Share on other sites
Quote:
 Original post by kyron21I don't think I'm really to a point where I want to dive into this yet, but am just curious. Using an Interpreted language (Lua, Python, etc.) in your C++. What are some advantages to it? I understand when programs get bigger, it can save compilation time when prototyping stuff (not having to recompile when you change your stuff written in Python)....but surely that's not ALL it's for.

Rebuilding and re-deploying a serious project can take hours (turnaround time).

This is for every single tweak, test or change. Contrast that to ability to change scripts once a minute, and simply see how it works.

Quote:
 What other uses are there? Also are there any pro's or cons to Lua and then pros and cons to Python.

More forgiving to mistakes, easier for scripters to pick up.

Quote:
 but just curious as to some of you guys uses for it, or/and if it is something I will need/should learn. I probably will just for fun regardless though.

A somewhat unusual application I've found was to put Lua on top of libpcap for network diagnostics. It made complex analysis of dunps quite convenient.

##### Share on other sites
When you embed a scripting language you can often make changes to a program while the program is still running. Hook in an interactive interpreter and you can run arbitrary scripts as will to test functionality immediately, like pretty much every "cheat code" that was actually intended as a debugging aid.

##### Share on other sites
It also makes translation into other languages a breeze.

Another thing I like, is that if I am debugging a certain script, I set it to load the script every time I activate it, that way I can make a change, save, and test, without even closing the application. Then when I release it, I make every script load on level load, and it is fine and dandy.

##### Share on other sites
One of the main reasons games usually embed a scripting engine into their game engines is so they can mass produce assets such as levels, sounds, materials simply and quickly.

Its primarily a Data Driven Programming solution when it comes to games.

Scripting languages allow an application to work somewhat independantly of the resources and assets used in the application.

For example, my game might want to run a script which sets up all the level's sound effects. My level might have a script that runs when it is loaded:

-- dungeon-level.luagetGame():runScript ("dungeon-sounds.lua")

The level's script may run a number opf scripts as well as doing its own actions such as creating the enemies.
-- dungeon-sounds.luasnd = getGame():getSoundManager()snd:loadSound ("ambient", "dungeon/ambient.mp3"):play ()snd:loadSound ("waterdrops", "dungeon/waterdripping.mp3")snd:loadSound ("fire", "loops/fire.mp3")

If scripting didn't exist, imagine hardcoding every level, every creature in those levels, all the sounds, materials, textures into the C++ code.

**shivers**

##### Share on other sites
It also can add replay value to your game through, think of how large the modding communities are for Half Life, Quake, and the like.

##### Share on other sites
USES:
debugging
Compilation time
on the fly changes
and good to use if making a game where any of it has a possibility to change later (enemies, music, sound effects, avatar graphics, levels, etc.)
So it sounds to me like a well planned game is really going to have the core mechanics in C++ and then the other stuff in the scripting language?

The more and more I read from you guys and other resources, It is starting to sound like you don't really want a lot of the game hard coded. I got to where I started saving character information (stats) in separate files so I could mod them without recompiling....then I took a step forward and started saving them in XML format so I could view them (Character information) in a Web Format (Just to see if I could), wrote an app to mod them, now this scripting stuff sounds like it takes the ENTIRE program a step further in roughly the same realm .....It would be quite helpful if classes/instructors went over these ideas early on. Well I guess that justs gives me more projects to go back and work on to see what I can do differently and to experiment with.

Thanks.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631428
• Total Posts
3000027
×