[w]tech combines next generation technologies like full dynamic lighting, voxel based terrain and bullet physics, which are brought to you via a self-explanatory user interface. We are thinking in innovative ways to combine the available technologies and ideas to an edgeless package. Visit wtechportal.com to get more information about the newest features integrated into [w]tech!

Report article RSS Feed [w]tech – Scripting Support

Now the shooting, killing, racing, jumping and running can finally begin.

Posted by unrealer2 on Aug 23rd, 2011

How can we force something to move or interact with the player? Since we can't just say it out, we have to tell the computer what it has to do on other ways. That it is: We have to write a script. Therefore we decided to use AngelScript as language because of the great support and a c++-like structure.


Scripts come in two forms

One is the GlobalScript, and the other one is the ContentMark-Script.The difference between them is that while ContentMark-Scripts are linked to a ContentMark on which they operate, GlobalScripts haven't such an anchor.
GlobalScripts are meant to be used as scripts which operate on the whole level, or to control the players. You can, though, build the same functionality of a ContentMark-Script into a Global-Script, but this leads to trouble: You'd have to register every single new instance there. This makes the script unusable for other levels and also it leads to much more complicated code than simply using a ContentMark-Script. As said above, ContentMark -Scripts are linked to a ContentMark after placing and can be accessed from inside. This way the same script can be used over and over again.


Getting something done

Now we want to show you, how you could implement a simple CM-Script which just rotates the given ContentMark. To do that, we have to create a new script-file in our browser:

ScriptingNews_1

That done, we can double-click our new file and the (rather simple) code-editor will pop up, waiting for us to get filled with code:

code:
#include "EngineScripts.wpk\ContentMark.ws"
 
class SimpleRotation : ContentMark
{
                // Variables and Methods go here!
};

This is the basic layout of every Script-File:

  • the #include directive to the parent-class
  • the class definition which has to match the filename
  • definition of variables and methods

Since we already called that script "SimpleRotation" we want it to do exactly that.
We'll surely need the Tick() -Function, so here we go:

code:
#include "EngineScripts.wpk\ContentMark.ws"
 
class SimpleRotation : ContentMark
{
     void Tick(float DeltaTime)
     {
                               
     }
};

As always, Tick() is getting called every frame of the engine when wanted. Makes it just perfect to animate stuff fluently. I also have to mention, that we are running the script-engine on it's completely own thread. That means that rendering-speed and script-speed aren't the same!
Back to our script now. We want our thing to rotate.To do this, we need to get access to the ContentMark we are linked to. This is done via the "GetCM()"-Function.
The call might look like this:

code:
#include "EngineScripts.wpk\ContentMark.ws"
 
class SimpleRotation : ContentMark
{
      void Tick(float DeltaTime)
      {
           GetCM().AddRotation(0, DeltaTime, 0);
      }
};

And hey! Our script is ready to get compiled and linked!

Scripts in [w]tech


ScriptingNews_1


Post comment Comments
Kamikazi[Uk]
Kamikazi[Uk] Aug 24 2011, 7:25am says:

Nice :D, i'm going to try to incorporate lua into my engine at some point.

+1 vote     reply to comment
[WuTz]! Creator
[WuTz]! Aug 24 2011, 1:41pm replied:

I was thinking about using Lua in [w]tech at first as well. But then it turned out I don't like it that much. So I did some research and found AngelScript as the better alternative for us.

Btw: I didn't know that you are the guy who made Bounce! Nice work! :)

+1 vote   reply to comment
blackmodeler
blackmodeler Aug 24 2011, 12:55pm says:

This engine looks better every time i see it! Awesome sauce, having said that AngelScript seems like a good choice

+1 vote     reply to comment
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Platform
Windows
Company
[w]tech team
Contact
Send Message
Licence
Creative Commons
Release Date
TBD
Engine Watch
Track this engine
News
Browse
News
Report Abuse
Report article
Related Engines
[w]tech
[w]tech Creative Commons TBD
Related Groups
[w]tech team
[w]tech team Developer with 3 members