Scripting languages?

BlitzMax Forums/BlitzMax Programming/Scripting languages?

Yahfree(Posted 2010) [#1]
Hey, this is a part of the programming world I have roughly no idea about.

I know they exist, such as perl, lua, etc.. But I don't know what they are, and what they do. I've googled them and can't seem to understand what's so great about them. Yet so many people praise them.

1. What exactly is the purpose? Can you give me an example where they would be convenient/used in?

2. How are they used?

3. Do they offer any benefits over the way I've been programming?

4. What can be done in them and what can not? for example, are they for purely the logic side of you're program or what?

Thanks for any answers :D


_Skully(Posted 2010) [#2]
A script language allows you to have your main program compiled and then dynamically change the behavior of objects that the script language is controlling.

So I could for example, give you a compiled copy of a game and let you mess with the object behavior in script files and have the executable file impose constraints on the objects being controlled.

Another nice thing is portability... Someone could create a script file for an object and then share that with others. Think of a robot game where the main exe is compiled so not pliable in any way.. but the script actually controls the robots within the constraints that the exe imposes on it... so you could share your control script across the internet and have duals.

Another example is extensions to paint programs that provide additional graphics processing functions.


Yahfree(Posted 2010) [#3]
Do you know of any tutorials that deal specifically with lua in blitzmax? and how to control objects?

I used to do something similar with a game. I had a .txt file that the program read and depending on what color was in the first line of text, it would change the color of a brick:

SetColor 200,200,200'Grey if the color is unrecognizable
Select line:String
   case "red"
     SetColor 255,0,0
   case "blue"
     SetColor 0,0,255
end select


Is it the same concept? if so, what makes the scripting language special?


degac(Posted 2010) [#4]
Hi, in the follow link there is my first implementation of LUA with a BlitzMax application.

http://blitzmax.com/Community/posts.php?topic=86728

The main advantage of using a script language as LUA is that BlitzMax application works 'as an engine' while in LUA script you give the freedom to the final user to use or not use or implement different things with the same 'engine'.

Some good tutorials on LUA and interfacing with Bmax applications (from easy to advanced) will be welcome!


_Skully(Posted 2010) [#5]
Thats kind of like translating functionality created in the base language to LUA.... another way to look at it.

Come to think of it, LUA is starting to sound interesting now that JIT is available


xlsior(Posted 2010) [#6]
Is it the same concept? if so, what makes the scripting language special?


Yes, it's pretty similar.

the big advantage of using a scripting language like LUA in your game, is that you can easily extend the functionality of the game without having to actually recompile things.

For example, that allows you to add new functionality, features, or even 3rd party user mods without the need to update / change / recompile / redistribute a new executable...

Especially useful for enabling end-user modifications, where you won't need to open up the actual source of your program, but provide them with an interface where they can programmatically change the behavior of the program (within certain boundaries, of course)


Htbaa(Posted 2010) [#7]
Everyone, please stop writing LUA, it's Lua.

What's in a name?
"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

Source: this page


GW(Posted 2010) [#8]
Everyone, please stop writing LUA

Yes! and start using BriskVM. ;)


ImaginaryHuman(Posted 2010) [#9]
Scripts are handy. A script language is a way of providing an extra `user interface` for the user, whereby so long as they are okay with writing text they can modify the scripts to alter the behavior of the game/app. Just as Blitz languages are largely targetted towards game development, you could have a script language which has specific functions to do things in a specific game, like moving a specific type of enemy, or adding gold to the amount collected, etc.. it can be really game specific stuff, or quite generic.

As a bare minimum you could have a script containing one line of code which calls a large function that handles the entire game. Like `DoTheGameLoop()`. On the other hand you could have really elaborate scripts that adjust all sorts of stuff to the point where the game looks and plays like an entirely different game - ala `modding`. Often the AI, animation, movement, gameplay features, level layouts, game structure, cut scenes, etc can all be written in a script language. If end users are allowed access to the scripts to be edited they can really tweak things how they like.

Another thing is that script languages can be fairly high level languages, so you can often do a lot of work with relatively few commands. Not always true, though. Some people like using C or even Asm-like languages for scripts. The main point is that the script is running `within` the application, like in a sandbox, usually interpreted or compiled on the fly. This offers certain benefits in terms of being able to modify stuff while the game is running, providing security against people doing stuff they shouldn't, allowing you to monitor the script functioning and intervene if it looks fishy, etc. Also stuff like the Java JIT `hotspot` compiler is able to monitor the efficiency of a piece of code and actually optimize it dynamically at runtime to produce code which is potentially even more efficient than handwritten C code (supposedly).

Another benefit to a script language is it can help speed up development because, although there is some time spent making the script language itself and making it `run`, you can design for yourself a higher level language than Blitz where you need to write much less code to achieve the results you want. That's pretty much what I'm doing to try to speed up development.

Also some script languages let you do things like access the web, write entire servers, even talk to other application. ARexx on the Amiga springs to mind which uses inter-process communication to let one program control another program via its `ARexx port`. So you could write scripts to let programs talk to and `operate each other`.


Czar Flavius(Posted 2010) [#10]
You could code the AI for your game in lua files, then people can tweek and customize the AI without needing to change your exe or viewing your source code. Could be handy for an adventure game - the entire story/scenario could be lua scripted.


Htbaa(Posted 2010) [#11]
@GW: I asked to stop writing LUA, not stop writing Lua code :-)


_Skully(Posted 2010) [#12]
Oh, stop being so case sensitive

lUa, LUA, lUA, LUa, luA, lua, LUA

Sorry... its just that I heard confronting your problems are the best way to resolve them.

Who calls a programming / script language "moon" anyway... maybe Sun would do something like that ;)


plash(Posted 2010) [#13]
Oh, stop being so case sensitive
Do you write "BLITZMAX"? :)


N(Posted 2010) [#14]
Lua is case-sensitive, so shame on you or something.


Brucey(Posted 2010) [#15]
But Skully is in-sensitive... or something.

:-)


Zeke(Posted 2010) [#16]
Back to topic?.. i have been using Lua+LuGI and its impessive how fast i can do things.. i can update about 10.000 objects in 10-20ms using ONLY LUA.. okay its only to call ALL objects lua function OnUpdate.. and i have things what are not coded yet and Update function is small... i DONT have to update ALL 10.000 objects, i can set object to "inactive" state and then not update that.. and when there is something to update .. just change state...

and this is Lua script:
--bat
bat={
	maxhp=50,
	hp=50,
	mindamage=5,
	maxdamage=10,
	level=2
}

function bat:OnUpdate()
	self.hp=self.hp+1
	self.hp=self.hp+math.random(10,20)
	
	if (self.hp%1000)==0 then
		print("HP="..self.hp)
	end
end

local object=AddObject("bat") --Add object Type
object:AddEvent("OnUpdate") --Add Event


and using Lua+LuGI i can add everything what i need to my game...

^^ after that i can add NPC bat to my game easily:

local npc=CreateNPC()
npc.SetType("bat")
npc.x=math.random(0,8192)
npc.y=math.random(0,8192)


^^ ok I need some more code to get that bat "alive".. but there are SO MUCH more code in bmax, so its easy thing... :D


N(Posted 2010) [#17]
I'll just go ahead and point this out: Lua-Scriptable Type


VicToMeyeZR(Posted 2010) [#18]

Lua is case-sensitive, so shame on you or something.



Apparently so is Plash. Almost acts like he invented the language or SOmeThinG


N(Posted 2010) [#19]
Apparently so is Plash. Almost acts like he invented the language or SOmeThinG
Are you mistaking Plash for Htbaa?


Htbaa(Posted 2010) [#20]
How am I (or Plash???) acting like I (he???) invented the language? Get real, VicToMeyeZR.


Yahfree(Posted 2010) [#21]
Back on topic... ?

What's LuGI? This is quite confusing :\


Htbaa(Posted 2010) [#22]
LuGI automagically generates bindings between BlitzMax and Lua for your types. Why would you want that? So you don't have to write all the bindings by yourself.