Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Work in Progress / JetScript - DBPro

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 29th Jan 2007 19:14 Edited at: 30th Jan 2007 00:30
Yes. Another scripting library. Infact, I'm just gonna keep posting them here till I come up with the ultimate one - you have been warned!

*Ahem* Anyway...

JetScript - Powerful DBPro scripting


This one is ofcourse better than all the others. I made JetScript firstly in one day (Saturday I think), and I thought of some descent features. So I scrapped that, and started again!

These are the features of this scripting library:
Multiple scripts
Send data from script to DBPro through 'return' command.
Calling functions from DBPro made in script
Table Arrays
Nested If Statements
Maths Evaluator
C Style syntax

I plan on making variables too. Also the ability to use the table data within the script, and to send data from DBPro to the script.

The best way to describle how it works, is by an example:

Script:


First of all, there is a big data table. These don't go in functions, only on the outside.
Next, you will notice the main() function. It is automatically called when the script it loaded.
Also, there is the return command. In the main command, I made it return some table data to DBPro. You can easily see how that's done

Then ofcourse there are the other functions.
I recommend you make small functions in your scripts, but not big important ones. You can see two half-descent usefull examples of functions there, the distance2D() and average() functions. Also notice the maths parser built in.


[edit]
Here are another two cool functions:


[/edit]

These functions can't be used by the script by the way. Only DBPro, sorry. I'm not a computer scientist or anything lol, I can't make everything!

Then there's another random function, just there to show off the nested ifs. (They don't have to be nested ofcourse lol).
The syntax in the ifs isn't like what youd expect. Here's a list of C++ comditions compared to my conditions.

== : =
> : >
< : <
!= : !

Not too different. I'm sure you'll get used to it (if you decide to use this)


The data in DBPro can be accessed easily. All commands in the script can be accessed (solves or unsolved - being where the parameters are solved incase they have any equations in them).
The data table data can be accessed using the jsGetTable() function, which uses the same syntax as that return way up there.
The return data can be accessed using the jsReturn() function.

Infact, here are all the functions. I will post a demo showing off the usefull ones, but I think you will have to download a script too.



All comments welcome (i.e. if you don't comment I will track you down and flush you down the toilet - peace )

Enjoy

Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 29th Jan 2007 20:16 Edited at: 29th Jan 2007 20:17
Nice one,

If it has variables Dark Basic Pro can easily be used for a new coding language!

^^Hint^^

BTW,when i read Jscript in your posts i keep thinking about JavaScript...

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 29th Jan 2007 20:22
Quote: "BTW,when i read Jscript in your posts i keep thinking about JavaScript..."


So do I

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 29th Jan 2007 20:34 Edited at: 29th Jan 2007 21:10
Dun dun dun! Error!

If you have this table:


It will work fine for "name" and "age", but not for each favcolor thing. It seems that the amount of sub-things has to be the same throughout... Time to fix that I think.


[edit]
Alright, fixed

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 29th Jan 2007 22:19
Tutorial

Here is a basic tutorial to show you how to use JetScript. It will be split into two parts. 1) Writing the script, and 2) Using DBPro to actually make use of the script.

Part 1: Writing your script
Scripts are really useful in games for many reasons. They can store data for levels, people, and in this case even perform simple functions. But when you think about it, how would you (with any language) store data for multiple things (well use people in this example)? Ofcourse! It's done using arrays!

JetScript has it's share of arrays, but are layed out differently than most languages. This is more like an array/UDT sorta thing, and is used into other scripts like LUA (check out Unity, by David T. It seems to be quite popular). These arrays are called Tables.
So, how would you use those tables (for those who don't know)? Well, it's pretty simple, and very structured.

Let's take me for this example. I want to put down every detail about me in a table.

That's me. That's all my information. That's my whole brain, on a table.

So let's look at what I did here. Well, the foundations of this is that elements within elements are stored between braces {}. The variable name is set using an equals sign, as you would expect.
So I started with my "Data" column. Inside that, I have more elements. One of them is about me, "Zotoaster". Within that, it has my name, age (young for my species), and favourite color (a sort of bright blue. Not really my favourite color in real life, but I often use it to make a sky colour in games. You should really try it). My favourite colour also has 3 elements. "r, g and b" (or red, green and blue).

All the actuall elements have to have a semi-colon ( ; ) after them. The actual braces dont.

So we have established that: Tables are arrays with named elements, and you can have infinite elements. Right? Cool.


Ok, I could go onto explaining how this works in DBPro, but I wont.

...

That will be explained in the second part.

Moving on from tables and chairs - We look at functions. Now I know most languages have functions, and in DBPro you can use them to to solve a few parameters and then spit out the value to use in a maths expression. Well, not because I'm nasty (which I am, believe me), you can't do that with this. I don't know whether to laugh or cry, because it affects me too... awww. Well yeah whatever, it is only a scripting language, so we don't want it doing all the work.

The functions are made pretty easily, and are then called by DBPro. You must first establish your main() function, as this is automatically run when the script starts. This is basically what it should look like:

Very complicated script there.

Now, because I've been working on this for oh, like, a day, there's not an awful lot you can do inside the functions - but you can do enough to make them useful. For example, I want a function to return the distance between two points in 2D. I could a) Do it the easy, handy, quick way and do it in DBPro. Or b) Do it the harder, more annoying inconvinient way, by using a script, just to please me

Here is how I would go about doing it.


That's it. Basic Pythagoras' Theorem. Us Greeks are such geniuses, aren't we Py'?

But that's not all. I have also added a feature never seen on the face of programming languages before - IF STATEMENTS!
Not just any "if statement", but also nested ones (ones which are inside each other, like a nest. Like, ifs living insde other ifs (cannibalism)).

Here is a very good example to show the functionality of if statements:


Alright, now, some more insight of functions (and other things):
Everything is in it's own block (the bit between two {} ). I don't know what it's actually called, so I'll call it a clause for now. I think that makes sense. The function has a clause, and the if statements have a clause. You have to enclose everything in these clauses, and they do not require a semi-colon ( ; ) at the end of them. However! commands do. You will have noticed the return command in the functions up there. Like all other commands, it requires a ; at the end.
The purpose of the 'return' command, is to directly send it's contents to DBPro. DBPro reads them, and you can access them, and then do you you like with them. Use them in the 'text' command. Use them to set an object size. Use them to ask your crush out on Valentine's day (if you are clever enough to). Do what you like, I, personally, don't care.

Ok, part one over. Let's move onto the next section - using the scripts in DBPro.


Part 2: Using the scripts in DBPro
Well, before you even can use any scripts, they must be set up. Do this using the.

...function. (All functions start wit 'js', for 'JetScript')

Now, you have to load the script.

-num = the number of the script (returns a variable, yeah)
-script$ = the file name of the script.

And yes, you can use multiple scripts here.

Alright, back to tables. If you want to load a table, there are but two ways.
a) Use the 'jsGetTable' function. Something like this (using the table we set up above):


I did it twice, because you can get different results. Table1$ here will just become "Alastair". Table2$ however will be "r=0;g=128;b=250;" as I have selected the whole clause.

b) Send the data to DBPro directly.
This is what it looks like in the script:

(and you don't use quotation marks)

Which leads me onto my next point - Using the 'return' command (in the script)
When you call return in the script, it will of course sent it's contents to DBPro. This will result in two things:
1) If it doesn't include quotation marks and does include arrows ->, it will return the table data that you send.
2) It will just send it's parameter (if it's an equation is will solve it unless it's enclosed in quotation marks.

Reading that couldn't be easier:

data$ will then just equal what is sent to you.


And lastly, to use the functions:
Well basically, functions just include the 'return' command, but not have parameters. These of course need to be substituted in. The way to do that is to use the 'jsCallFunc()' function in DBPro. Something like this:

That basically lets the script send it's contents, but it will replace any variables of the function with the parameters you send it


So that's the tour over. Everyone off the bus and give it a go yourselfs. I intend of updating it quite alot, so don't get too used to it...


Here is a basic script to test out:



And the code (with updated functions):



Enjoy

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 30th Jan 2007 00:24
Updated the functions.



Now, when refering to a table, you can either use arrows -> or dots . if you're inclined But you can't do both...

Just felt like doing that heh.

Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 30th Jan 2007 11:24
Ah,nice new functions dude!

I will play around with this and well,i will find a use for it once.

Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 5th Feb 2007 18:59
Was this what you were talking about on MSN? Thats amazing.

Cheers,

-db


"There's no such thing as a stupid question, just stupid people."
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 5th Feb 2007 20:27
Haha, this is old already Well not really, I'm working on an actuall programming language type thing now. These were all script, and you could load many at a time. Problem with that is I couldn't make any one single array for variables, and any other method would be slow. So yeah, I'm working on my programming language just now, but I'm "borrowing" bits of the code from this

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 7th Feb 2007 01:41
I have been using JetScript in a simple 2D Tile-Based RPG I'm making to helo Chris Franklin along, and I have to say it's coming in very usefull, especially the tables.

I have only used it so far for level design, for example:



Here is the DBPro code to load a level. The loadLevel() function call is near the top, so you can change the directory of the script.


Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 13th Feb 2007 01:54
I have taken a break from taking a break from programming and restarted... Now you can use the functions you create within your code, like this:



So if you call the main() function it will notice print and it will read it, and because it finds sqrt inside that it will call the sqrt function and solve. It works pretty well

Haven't implemented variables of ifs yet in this one though..

Silvester
18
Years of Service
User Offline
Joined: 7th Dec 2005
Location: Netherlands
Posted: 13th Feb 2007 14:28
Cool,

i should learn how to make a scripting language once...

-Prince Of Darkness
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 13th Feb 2007 21:54 Edited at: 14th Feb 2007 01:29
Woohoo!!

I remember not too long ago when writing a scripting language, and I wanted to make an object command that would include sizes, positions, and, colours (etc). Problem with the colours was that I tried to make a RGB command somehow, but since that was a command within a command, I couldn't figure it out. Well, now it seems to work fine

Example:


So the functions can have multiple parameters This is a good step forward for me lol.


[edit]
Prince of Darkness, I may write a tutorial some day


[edit]
Alright, got if statements working, which gave me a good idea for a quick work-around for basic arrays.
Something like this:


Just a function, and you can set what it will return depending on which number is passed to it.

Login to post a reply

Server time is: 2024-11-17 11:17:48
Your offset time is: 2024-11-17 11:17:48