Mythruna
April 24, 2024, 09:25:29 PM *
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: Getting Started (WIP)  (Read 27786 times)
Sunjammer
Newbie
*
Posts: 16



View Profile
« on: February 04, 2012, 08:42:45 AM »

I'm trying to collate information on Mythruna scripting (and possibly modding Mythruna generally) for those of us who perhaps don't have a great deal of the Java/Groovy experience but who might be interested in scripting (or modding) for Mythruna.  What follows is very much just intended to get the ball rolling and would benefit from those of you that actually know stuff and/or have used stuff. Once it's been knocked into shape we can migrate it to the wiki.

1. Download the latest version of Java SE SDK

Downloadhttp://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html#javasejdk
Guidehttp://www.oracle.com/technetwork/topics/newtojava/documentation/index.html
APIhttp://docs.oracle.com/javase/7/docs/api/

2. Download the latest version of Groovy SDK

Groovy a dynamic language that runs on the Java Virtual Machine (JVM) and is one of the scripting languages supported by Mythruna engine.

Download http://groovy.codehaus.org/Download
Guide http://groovy.codehaus.org/Getting+Started+Guide
API[link required]

3. Download an IDE

An Integrated Development Environment (IDE) is not essential however it can make life a lot easier with features such as syntax highlighting, auto-complete, debugging, etc. For a quick comparison of the different Java IDEs see this Wikipedia article.

We suggest using one of the following free IDEs:

3.1 Eclipse IDE for Java Developers

Downloadhttp://eclipse.org/downloads/
Groovy pluginhttp://groovy.codehaus.org/Eclipse+Plugin
Guidehttp://help.eclipse.org/indigo/index.jsp

3.2 IntelliJ IDEA Community Editions

Downloadhttp://www.jetbrains.com/idea/download/index.html
Groovy Pluginhttp://groovy.codehaus.org/IntelliJ+IDEA+Plugin+by+JetBrains
Guidehttp://www.jetbrains.com/idea/documentation/index.jsp

3.3 NetBeans IDE 7.1

Downloadshttp://netbeans.org/downloads/index.html
Groovy Pluginn/a
Guidehttp://netbeans.org/kb/index.html

4. Review the Sample Scripts

« Last Edit: February 04, 2012, 08:52:06 AM by Sunjammer » Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #1 on: February 04, 2012, 08:55:04 AM »

Thanks a ton for getting this ball rolling.

Another thing I will point out, groovy comes with its own console application:
http://groovy.codehaus.org/Groovy+Console

This is useful for just running little groovy scripts and seeing what they do, trying out little syntax snippets, etc..

One of the ultimate problems you will run into with Mythruna and scripting is that Mythruna heavily adds to the scripting language to make it more game specific.  These things won't be available in a console like that...

However, eventually I hope to add an offline script builder mode that lets you run Mythruna with that groovy console embedded in a separate window.  This way you could check and tweak your scripts on the fly.  That is the nice thing about the Groovy Console being embeddable.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #2 on: February 04, 2012, 08:58:34 AM »

Also note: for the time being it is better to stick with JDK 6 documentation to be safe.

Mythruna still supports JDK 6 and uses Groovy 1.8.  So those are the versions you should target when running things outside of Mythruna.
Logged
Sunjammer
Newbie
*
Posts: 16



View Profile
« Reply #3 on: February 06, 2012, 05:48:36 AM »


Bearing in mind that this article will be aimed at the non-Java programmer what other steps are required to get started? Do they have to set environment variables? Copy jar files from A to B? Extract files from jars? In short what have I missed?

Has anyone used/is anyone using any of these IDE with/without the plugins and could provide an insight into their relative strengths/weaknesses?

"Getting Started" is really a combination of "getting everything you need downloaded, installed and configured" and "writing, compiling and running your first script". In other words we want to take a reader has, until now only played Mythruna to executing a "Hello World" script as painlessly as possible to avoid potential modders giving up before they get started. Any ideas  you have regarding that would be welcome.

Similarly although I currently have "Review the Samples Scripts" in as the final step it probably would be better being moved to/part of a "What/where next" step.
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #4 on: February 06, 2012, 06:35:20 AM »

This is really getting cool.  Thanks for pushing on this and I'm sorry I haven't been more responsive lately.  I've worked approximately 30 hours in the last three days trying to get a day-job release out this morning.

Back to the business at hand, though. Smiley

Now, the cool thing about the way all of this is setup is that you technically already have everything you need to develop scripts when you download Mythruna.  Presuming you don't want to jump right into "Selecting an IDE", you can get from 0 to "Hello, world" and just a few clicks.

Step 1: open up a DOS command prompt.

If you are not familiar with this at all then you should consider taking some other baby steps first but anyway, in Windows you can click "Start->Run" and type cmd.exe.

Step 2: go to the directory where you've unzipped Mythruna.

Step 3: Run this command:
java -cp Mythruna-20111223.exe groovy.ui.Console

(replace the version as appropriate)

This should pop up a window that looks like this:


Step 4:
In the top part, type:
Code:
print "Hello, world"

Step 5:
Click the "Execute Script" button like in this picture:


Now you are running groovy.

The interesting thing about this approach is that you also have access to all of the internal libraries that Mythruna uses.  It doesn't help a whole bunch but someday it might.

Other platforms:
The same thing can be done on Linux and Macs... you just change the java command to point to Mythruna.jar instead of the .exe
java -cp Mythruna-20111223.jar groovy.ui.Console

For just fooling around in Groovy to get a feel for it, the above is the single easiest way to get started.
Logged
BenKenobiWan
Friendly Moderator
Donators
Hero Member
***
Posts: 674


Jesus loves you!


View Profile
« Reply #5 on: February 06, 2012, 09:44:45 AM »

If I am currently studying C++, does that at all help? I don't yet have much of any experience with that (I'm on chapter 5 of 22), but is the program structure similar?
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #6 on: February 06, 2012, 10:00:19 AM »

If I am currently studying C++, does that at all help? I don't yet have much of any experience with that (I'm on chapter 5 of 22), but is the program structure similar?

If you've never studied a programming language before then there is a lot you will learn that will apply universally.  However, the syntax similarities between C++ and Groovy are probably ultimately more confusing than anything else.  But Groovy is a lot easier than C++ to play around with... and safer too.
Logged
Sunjammer
Newbie
*
Posts: 16



View Profile
« Reply #7 on: February 06, 2012, 02:48:14 PM »

Great post about the Groovy Console (probably the start of a second wiki article right there) but please don't feel you have to respond while you are busy at work. I suspect it will be a while before people are demanding a "Taking the Myth out of MythScript" type article. Also hopefully there's a few other people here that I can prod for Java/Groovy knowledge (otherwise I'll be grabbing my textbooks and then Maker help us all)!

Now, while the Groovy Console is definitely cool for us programming types, I think to capture a potential modder's imagination our first "Hello World"1 script has to appear in game. Affecting the game is what it's all about! Ideally "Hello World" would be displayed in the Mythruna equivalent of NWN's floatytext or .Net's MessageBox GUI. The next step could then evolve that script into one that accesses the some game data and perhaps says "Hello <playerName>" and evolve it again to add some additional information like "you have been playing for <playTime> minutes".

Once they have a couple of basic scripts under their belt the next tutorials could look at different aspects of the API including things like the water repair tool; or get/set time of day; get a list of people logged in; make me drunk (every game needs that); change fog colour, oh, no, wait ... that was NWN. Doh!

Obviously we'll know more about the cool things as the API starts to become defined and we get a feel for things that are useful, fun or just plain cool.
____
1 I just thought it should be "Hello Mythurna"  Wink

Logged
randomprofile
Global Moderator
Sr. Member
*****
Posts: 265


View Profile WWW
« Reply #8 on: February 06, 2012, 04:52:13 PM »

C++ is ALOT more powerful and can be used to make raw OS systems... or 3D engines. But I'm not sure about groovy my guess is you can make basic programs with it?
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #9 on: February 06, 2012, 07:17:44 PM »

C++ is ALOT more powerful and can be used to make raw OS systems... or 3D engines. But I'm not sure about groovy my guess is you can make basic programs with it?

Groovy compiles to Java classes so in theory it _can_ be as fast as Java... but in general it will be slower than Java.

For 3D work, the GPU is doing most of the work anyway.

I wasn't suggesting that he stop learning C++... just giving advice on what knowledge will and won't transfer.  The truth is, once you get used to wrapping your code blocks in { } then all kinds of things make sense. Smiley
Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #10 on: February 06, 2012, 07:28:23 PM »

Great post about the Groovy Console (probably the start of a second wiki article right there) but please don't feel you have to respond while you are busy at work. I suspect it will be a while before people are demanding a "Taking the Myth out of MythScript" type article. Also hopefully there's a few other people here that I can prod for Java/Groovy knowledge (otherwise I'll be grabbing my textbooks and then Maker help us all)!

Yeah, I got my deliverable out (though there will certainly be another one soon because it's a buggy piece of...) and I was still riding the release adrenalin. Smiley   So it was nice to have a quick post.

Now, while the Groovy Console is definitely cool for us programming types, I think to capture a potential modder's imagination our first "Hello World"1 script has to appear in game. Affecting the game is what it's all about! Ideally "Hello World" would be displayed in the Mythruna equivalent of NWN's floatytext or .Net's MessageBox GUI. The next step could then evolve that script into one that accesses the some game data and perhaps says "Hello <playerName>" and evolve it again to add some additional information like "you have been playing for <playTime> minutes".

Agreed.  The console was just about getting ones' groovy feet wet without necessarily having to pull up a big IDE.  That is also the same console that I will launch "in game" in a script-developer mode when I get to that point.  So some familiarity is probably a good thing.

My first stickied example shows how to add a custom command for use in game.  But there is perhaps even a simpler "Hello, Mythruna" type of script.  One that just says hello when you start the game:

Code:
on( playerJoined ) {
    console.echo( "Hello, Mythruna!" )
}

Copy that into a mods/scripts directory under where the mythruna exe is and when you join a game it will say hello.

The example #1 shows how to get the player name, though in single player the player has no name yet.  That example will get simpler soon.

Once they have a couple of basic scripts under their belt the next tutorials could look at different aspects of the API including things like the water repair tool; or get/set time of day; get a list of people logged in; make me drunk (every game needs that); change fog colour, oh, no, wait ... that was NWN. Doh!

Smiley

Obviously we'll know more about the cool things as the API starts to become defined and we get a feel for things that are useful, fun or just plain cool.
____
1 I just thought it should be "Hello Mythurna"  Wink

Yeah, because you have direct (currently unsandboxed) access to the game code, you can do all kinds of odd and wonderful/dangerous things. Smiley  The trick will be sorting out what people want to do a lot and providing a nicer API for it. Smiley
Logged
randomprofile
Global Moderator
Sr. Member
*****
Posts: 265


View Profile WWW
« Reply #11 on: February 07, 2012, 09:41:44 AM »

simple in game pop up boxes? is a most... but I think your priority should be making sure the scripter not have too much power like the ability to crash your client when you join.

***EDIT***
Also I have a question on how groovy works in game, lets say I make a question say "Are you a cool" Click Yes or No and then store the answer to a SQL Database.
And you need to temporarily use the variable which lets say is $derp. Will this variable work for everyone without collision or will one need to write an Array adding function where it adds you a huge array where every user is stored on whether he/she is cool or not? AKA $derp[sleepercell42]=yes or something like this...
« Last Edit: February 07, 2012, 09:49:20 AM by SleeperCell #42 » Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #12 on: February 07, 2012, 09:46:46 AM »

simple in game pop up boxes? is a most... but I think your priority should be making sure the scripter not have too much power like the ability to crash your client when you join.

In multiplayer, all of the scripts run on the server.  There is a small exception to this but those are scripts you install, not the server.

I mean, the server can probably still crash your client by doing something strange (for example, simply teleporting you all over the world rapidly will probably eventually crash the client)... but the only harm there is "Gee, I guess I won't connect to their server again."
Logged
randomprofile
Global Moderator
Sr. Member
*****
Posts: 265


View Profile WWW
« Reply #13 on: February 07, 2012, 09:50:28 AM »

Lol I already edited my other post, but I still wanna get your attention Cheesy


***OTHER EDIT****
Also I have a question on how groovy works in game, lets say I make a question say "Are you a cool" Click Yes or No and then store the answer to a SQL Database.
And you need to temporarily use the variable which lets say is $derp. Will this variable work for everyone without collision or will one need to write an Array adding function where it adds you a huge array where every user is stored on whether he/she is cool or not? AKA $derp[sleepercell42]=yes or something like this...

***EDIT 2***
Lol well of course I meant a server script lol
P.S what are you doing up so early Cheesy or is it already late where you are...
« Last Edit: February 07, 2012, 09:54:25 AM by SleeperCell #42 » Logged
pspeed
Administrator
Hero Member
*****
Posts: 5612



View Profile
« Reply #14 on: February 07, 2012, 10:19:35 AM »

Lol I already edited my other post, but I still wanna get your attention Cheesy

***OTHER EDIT****
Also I have a question on how groovy works in game, lets say I make a question say "Are you a cool" Click Yes or No and then store the answer to a SQL Database.
And you need to temporarily use the variable which lets say is $derp. Will this variable work for everyone without collision or will one need to write an Array adding function where it adds you a huge array where every user is stored on whether he/she is cool or not? AKA $derp[sleepercell42]=yes or something like this...

Yes, you currently have ways you can easily store data associated with a player that is private to them.  It takes more steps than it should and that's one of the things I will fix (maybe in this release).  I have shown someone that in the correction of one of their scripts... though I don't have the post handy.

There will be ways to have all of the following:
-global variables available to all scripts  (only exists in a hacky way but I may decide this is too dangerous anyway)
-global variables available to a specific script (any variables defined in the script are global to the script, ie: same variable for all players)
-in-memory data associated with a player/connection (this requires more code than it should and is what I talk about above.  This data only lasts while the player is logged in)
-persistent data associated with a player (in multiplayer this already exists for string, int, etc... primitive types.  playerData.someValue = "foo"; playerData.save())

One I'm on the fence about:
-persistent data associated with any entity (the entity system supports this but it's not as straight forward as the playerData example above)

In Neverwinter Nights, we could have any local variable we wanted on any object.  I can make some nice functions for doing this within the entity system but I have to see how well it performs.  One thing you couldn't easily do in NWN was have random objects just to stick things on (well, you could but they cost you)... In Mythruna's entity system, an entity is free (literally costs nothing) until it has data associated with it.

This may lead itself to different strategies.

***EDIT 2***
Lol well of course I meant a server script lol
P.S what are you doing up so early Cheesy or is it already late where you are...

It's now just after noon here.  I live on the east coast USA.  My really odd sleep schedule sometimes confuses things. Smiley  For example, this past weekend it seemed like I was sleeping in 2-3 hour shifts.  I finally got my day-job release out, ran down off the adrenalin, went to bed at noon and then wasn't aware of anything until after 6:30 PM. Smiley
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!