Page 1 of 1

Scripting language?

Posted: 09 May 2005, 04:47
by Bear
what scripting language would we be using for TMW? I personaly like athena scripting code, but that is because iv been working with it for some time... but im just wondering what type of scripting language we will be using?

BTW, i made a slot machine npc :D

seven posibilities to win, 1,1,1 ,2,2,2, ,3,3,3,...so on
the npc generates 3 random numbers.

Posted: 09 May 2005, 06:50
by maci
well for now we have squirrel on the server ..but i dunno if this what we going to use

http://squirrel.sourceforge.net/

Posted: 09 May 2005, 09:14
by Bjørn
Yep, initial support for Squirrel is present now and we're still considering using Lua or Ruby. Little to no work has been done on figuring out how the scripts will actually interface with the engine, so this area is still rather unclear.

Posted: 09 May 2005, 18:50
by maci
we could develop some stuff to make it easier too

like npc generators and such things

Posted: 09 May 2005, 23:38
by nym
Yeah, currently Squirrel is being used as a "sandbox" scripting language for testing. But by no means will be be the only language available on TMW server (the language of choice will be compiled into TMW server via defines, or possibly we could have multiple scripting environments chosen at runtime). A Ruby binding would exist now if i could find some decent documentation on it (i haven't been able to find good embedding documentation, if you know of any [which do not use SWIG] give me a shout :)).

While i am only using Squirrel for testing at the moment, it could might as well replace Lua, as Squirrel is a Lua clone with _many_ similarities.

The way i currently think scripting would work is this (most actions will be deferred from server into scripting, only having the server do essential tasks and provide an interface to the scripts). So each Being, Skill, etc. will have their actions executed by a script (and the server will provide a necessary means to do so). By doing this we should have a highly extensible server (and by deferring many tasks into higher-level scripting realm we should hopefully have a more secure server [buffer overflows less feasible etc]).

Posted: 12 May 2005, 11:56
by nym
If you are interested in looking at Squirrel, check out squirrel.sf.net . I have worked a little on the scripting system and currently here is what an item script will look like (this is still in the design/testing phase, so it will most likely change a bit).

Code: Select all

// Define required variables
name <- "Potion";
type <- 0;

attack <- 0;
defenst <- 0;
luck <- 0;
vitality <- 0;

//

function use()
{
    print("Item " + name + " was used\n");
    setHealth(getHealth() + 10);
}
The item, as you may have guessed (or read) is a potion. Each different type of script will have a library of functions available to use (there will also be a standard library which will consist of all the common functions). Also note that certain types of items will not require all the variables to be defined (many defined above are for illistration purposes only).

Currently the scripts dont do alot, as what they are supposed to control hasn't been implemented fully :) (i am starting the scripting early to allow total integration of scripting into the server to allow maximum customizability).

The way the scripts work is:
a) the script is compiled
b) the main body of the script is executed (everything which can be executed)
c) the script finishes running, leaving the registered variables in memory.
d) the special functions defined are called for their appropriate action.

The name <- value; syntax is the "new slot in root table" operator, which creates a global variable which will persist until the virtual machine is destroyed.

EDIT: Any suggestions appreciated :)

Posted: 12 May 2005, 12:23
by Bjørn
An example of what the potion script could look like in Ruby:

Code: Select all

class Potion < Item
  def use(being)
    being.health += 10  # Increases health for target being
    destroy             # Destroys this item
  end
end
Whether we go with class or instance methods depends on wether we want to allow the scripts to hold additional item state information. This affects the way we'd store/retrieve item instances from the database and general item management. The above example defines an instance method.

Posted: 13 May 2005, 00:27
by Bjørn
Hmm thinking about this idea it occured to me specifying item usage effects in scripts is probably not the best thing to do. This is because not only will the server need to execute it but the client will also need to be able to display to the user what the effects of using the item are beforehand. Hence a more fixed XML approach example now, which we should probably evaluate and prototype a lot before implementation.

Code: Select all

<item id="16" name="Potion" value="200" ...>
  <use target="self">
    <effect type="heal" duration="0" amount="10"/>
  </use>
</item>

<item id="55" name="Helm of the bear" ...>
  <equip>
    <effect type="armor" amount="2"/>
    <effect type="strength" amount="10"/>
  </equip>
</item>
Scripts would still be used to describe more complex things that the client need not know about in advance.

Posted: 13 May 2005, 01:19
by Blorx2
Nym, I'd like to point out that in your code, "defense" is spelled wrong

Posted: 29 Jul 2005, 17:28
by nayr
ruby! Ruby! RUBY! RRRRUUUUUBBBBYYYY!!!!!

Ruby is one of the best scripting languages. ever.

Posted: 30 Jul 2005, 10:56
by nym
This is quite an old thread, but i will point out that Ruby will be used primarily for scripting on the server (although we won't rule out any other possibilities for alternate language support).

Posted: 06 Aug 2005, 01:51
by Scooterman
Where i can find info about the current variables used in the server? Or some examples of working scripts? I?m really interested in helping developing scripts.

cya

Posted: 06 Aug 2005, 08:08
by ElvenProgrammer
Those are the scripts we're using at the moment on our server http://cvs.sourceforge.net/viewcvs.py/t ... -data/npc/

PHP :)

Posted: 27 Sep 2005, 20:13
by criptos
There a good amount of documentation to make a php binding to a c++ lilbrary...

And also, you could have all the other php functionality, for example, NPC using scripts could access database by they?re own :) and check things at the database stats...

I belive ruby could do the trick, but I?ve reading about themana world for a week, and I really have found little information about ruby compared to php...

Just a tougth.