Mythruna
April 25, 2024, 04:36:01 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome to the new forums. See "Announcements" for a note for new users.
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Scripting console...  (Read 19187 times)
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« on: February 16, 2012, 10:57:22 AM »

This was something I slipped in an initial version of to the 20120216 release.

I've started hooking up the cool Groovy Console window up directly to the game when it is run in a special builder mode.  The hook up of the environment and API is not 100% yet but I hope to fix that in the next release.  There is already a lot of stuff that you can do, though.

If you run any of the mythruna executables from the command line and pass -script as an argument then it enabled build mode.

Mythruna-20120216.exe -script

Then run the single player game.

Once in there you should be able to open the chat bar and type:
/script

This will pop-up the groovy console window.

For fun, try running this code in there:
Code:
echo "My location is " + getLocation()
echo "My name is " + player.name

(typing that from memory)

Then click the little "Execute" button in the right side of the Groovy Console's toolbar.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #1 on: February 16, 2012, 02:57:07 PM »

In the next release, the environment in the scripting console will be the same as in the init scripts.  I'm not planning to release again before Monday at the earliest (and hopefully Monday).

If any of you scripting guys wants access to it earlier than I can make an early access release.  Just let me know.
Logged
Sunjammer
Newbie
*
Posts: 16



View Profile
« Reply #2 on: February 17, 2012, 07:23:00 AM »

I'll have dabble with it over the weekend.

I'm also intrigued to know if there is a reason why the player's location is accessed using getLocation rather than say player.location or player.getLocation? Are there going to be global methods (for want of a better description) which can be called without an object or is there an implicit this as in this.getLocation?
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #3 on: February 17, 2012, 09:27:08 AM »

I'll have dabble with it over the weekend.

I'm also intrigued to know if there is a reason why the player's location is accessed using getLocation rather than say player.location or player.getLocation? Are there going to be global methods (for want of a better description) which can be called without an object or is there an implicit this as in this.getLocation?

I could probably unify it at some point but it gets weird.  Bear with me for a second while I explain...

Objects are entities with positions... which means in the entity system they have a Position component that has their location and their orientation.

println "Location:" + someEntity[Position.class].location + "  Facing:" + someEntity[Position.class].rotation

These are common enough things that I may collapse them to someEntity.location and someEntity.rotation... especially since there are potentially two ways to get them on an entity.  (I did this with the Name component which is why someEntity.name works.)

In the case of objects that are moving (like the player or like physics objects), you have to ask for a position and location at a specific time.  I definitely don't want expose the scripter to that because it gets really long:

println "Location:" + someEntity[TimeBuffer.class].getLocation(simulationTime)

(where simulationTime is the time of current simulation step... so everything is consistent.)

It would be better to overload .location and .rotation to do this automatically in the cases where it is a mobile object.  Though it does make .location and .rotation slower overall to do that check.

The player, on the other hand, is kind of special in this case because that entity isn't yet handled by either of the above systems.  Eventually the player will be a TimeBuffer based entity just like any other physics object.  In the mean time, the player-level getLocation/setLocation on the single player game is very different than the one in multiplayer so I tried to hide it away with the API.  These are some of the original scripting functions, though.

It's quite likely that they will be deprecated once the player is a real physical entity just like any other mob.

There are a few global functions like this, though.  I will post a follow-up with the functions that exist so far and how likely they are to live to release.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #4 on: February 17, 2012, 11:37:57 AM »

Note: most of these require the new unreleased version of the game to work.  I can provide a prerelease to anyone wanting it.
Code:
// Logs a warning to the client.log or server.log
warn( String msg )

// Register a block of code with the specified event or events.
// Most of the -init scripts will be mostly these.  They can be used in the script
// console but then you should keep track of the result so that you can remove
// it before adding another hook or you will just keep adding more hooks.
EventListener on( EventType type, Closure doIt )
EventListener on( List types, Closure doIt )

// Removes a previously registered hook for the type or types.
void removeHook( EventType type, EventListener hook )
void removeHook( List types, EventListener hook )

// Defines an action that can be run later by group and
// name.  This is one of the building blocks of the user-invoked
// tools as well as any eventual object-specific actions.
// When an action is reregistered for a given name and group
// then it has access to the previous version also.  There is
// currently no way to remove one of these at runtime once
// registered so (right now) using this in the scripting console
// is not advisable.
void action( Map args, Closure doIt )

// A specific type of action that has no specific group and
// will always be run targeted to an entity.
void entityAction( Map args, Closure doIt )

// Adds a command to the user's shell.  This will be changed at
// some point to be shell.addCommand() instead.
void addShellCommand( Shell shell, String name, String description, String help, Closure exec )
 
// Removes the "object" components from the specified entity and does its
// best to remove the entity completely.
void removePlaceable( EntityId e )

// Returns the numeric cell type of the x,y,z location
int getCellType( double x, double y, double z )

// Returns the numeric cell type of the Vector3i location.  Some APIs and hooks
// return positions as Vector3i so this is for convenience.
int getCellType( Vector3i loc )

// Sets the numeric cell type
void setCellType( int x, int y, int z, int type )
void setCellType( Vector3i loc, int type )
BlockType toBlockType( int blockType )
MaterialType toMaterial( int blockType )

Any of those with the last argument "Closure" means that they take a code block "{ some code }"

so,
Code:
entityAction( name:"My Action" ) {
    // Some code to run when "My Action" is invoked.
}

There is of course a ton more that you can do from scripts.  Those are just the convenience APIs that I've built in so far for "root level" stuff.

The other stuff is harder to document.  For example, there are a dozen or so "components" for the entity system.  "Components" are like typed blocks of data that you can associate with an entity... like Name, Position, etc..

Here are some of them off the top of my head:
Code:
ClaimArea
ClaimType
CreatedBy
InContainer
ModelInfo
Name
OwnedBy
Position
Volume (in the physics sense)
Mass
MassProperties
BodyState

And there will be a bunch more eventually. 

Some are sort of player specific as associating them with the player entity will cause things to happen on their UI.

For example, ToolActions contains the list of tools that the player has in their mouse scroll wheel set.  (This is specific to 'build mode' and will change with 'game mode' but that's another topic.)

More universally, a RadialActions component added to a player will cause their radial menu to popup.

DialogPrompt is the same.

It is my intent to provide more convenient access to these components... but the raw approaches are available even in the scripting console:

Code:
// change the name of some entity
entity << new Name( "My Name" )

// get the container of some entity
println entity[InContainer.class].parentId

I haven't wanted to add too many wrappers at this point because things are moving around and it makes maintaining a wrapper API less productive.

Modders can also create their own components and I want to give some thoughts to how they could add their own convenience API also.  So if _I_ have a way of mapping entity[InContainer.class] to entity.container then the modders should have similar abilities.

I'm spending a lot of time thinking about this lately and the scripting console is a big start to helping me get things cleaned up and a little more user friendly.  Specifically, being able to add and remove hooks is a critical feature and being able to easily add and remove entire plug-ins will be also.  I have a beginning design for a more formal plug-in system that will let hooks and actions be associated with a plug-in object that can be loaded and unloaded (within reason).

This weekend I'm focusing on fleshing out "game mode"... this will lead to a lot of scripting goodness also.

Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #5 on: February 17, 2012, 03:26:57 PM »

I put a build up for another user to test a fix for a problem they were having.  It's not an official release but it does have an updated scripting console environment:

http://mythruna.com/distros/Mythruna-20120217-Windows.zip
http://mythruna.com/distros/Mythruna-20120217-Linux.zip
http://mythruna.com/distros/Mythruna-20120217-MacOSX.zip

When I have the basics of "game mode" done then I will cut another official release.
Logged
Sunjammer
Newbie
*
Posts: 16



View Profile
« Reply #6 on: February 17, 2012, 03:42:34 PM »

I read your original API stuff on the way home form work but didn't have time to reply. I come here to type a quick "thanks for the info" type note and there was even more scripting goodness and a new build. There goes my last night of SWTOR!
« Last Edit: February 17, 2012, 03:49:14 PM by Sunjammer » Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #7 on: February 17, 2012, 05:16:45 PM »

I posted a lot of info in this thread but I'm not sure it's terribly useful yet. Smiley  Maybe not useful enough to derail SWTOR at least. Smiley

What I need to do is add some special scripting console commands that makes it easier to poke around without documentation.  As it stands, I posted those component lists but then you'd have to guess how to use them unless you were a pretty experienced Java developer that knew how to dig into .class files.

Something else I will mention...

There is much of the current Mythruna functionality that is implemented as scripts embedded in the app.  A .jar file is just a .zip file... and lib/Mythruna-core.jar will have the build-in .groovy files in it.  I can't promise that they are pretty but they might be interesting to look at.
Logged
DerEine
Newbie
*
Posts: 1


View Profile
« Reply #8 on: March 27, 2012, 12:52:15 PM »

There is a getLocation() method. Is there also a setLocation() method? I would really like to use it.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #9 on: March 27, 2012, 03:56:02 PM »

There is a getLocation() method. Is there also a setLocation() method? I would really like to use it.

Yes, setLocation(x,y,z) should work in both single player clients and on a multi-player server.

It's not pretty from the player's perspective, but it works.
Logged
Thanos
Jr. Member
**
Posts: 60



View Profile
« Reply #10 on: April 13, 2012, 04:09:19 PM »

script console works fine in single player but it gives me an error in multiplayer mode and the game exits unexpectedly when i write /script. I got an error log file too i can upload if you need it paul
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #11 on: April 13, 2012, 04:25:06 PM »

script console works fine in single player but it gives me an error in multiplayer mode and the game exits unexpectedly when i write /script. I got an error log file too i can upload if you need it paul

The script console will only ever work in single player because the scripts run on the server in multiplayer.
Logged
Thanos
Jr. Member
**
Posts: 60



View Profile
« Reply #12 on: April 13, 2012, 04:41:20 PM »

oh I didn't know that i guess its ok then Smiley I may need to learn groovy after all seems pretty interesting
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #13 on: April 13, 2012, 05:59:54 PM »

oh I didn't know that i guess its ok then Smiley I may need to learn groovy after all seems pretty interesting

It's kind of a neat language.  I like it because I can twist it to my needs. Smiley

Technically, there is a set of scripts that runs on the client even in multiplayer but the environment is way different than the one that the single player client and multiplayer server share.

These special client side scripts are really for adding things to the UI or tweaking things to that effect.  I used them to implement the /flora and /trees commands that are only ever client-side.
Logged
chessikr
Newbie
*
Posts: 7


View Profile
« Reply #14 on: August 10, 2012, 07:35:15 PM »

i would definitely like to see some documentation for scripting, there are so many things i would like to try but being unfamiliar with java and thus groovy it has been difficult trying to decipher what the xyz.groovy files actually do without being able to see the code for the #includes etc.
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!