Re: Introducing surgescript

Timeout

One of the most useful commands of the old API was on_timeout. Basically, it allowed to change the state of an object after a number of seconds passed. The same functionality can be achieved today in SurgeScript using timeout(): smile

object "Application"
{
    state "main"
    {
        Console.print("Now on the main state. Please wait 4 seconds...");
        state = "wait1";
    }

    state "wait1"
    {
        if(timeout(4.0)) // will wait 4 seconds to change the state
            state = "cool";
    }

    state "cool"
    {
        Console.print("Cool! Now wait for more 8 seconds...");
        state = "wait2";
    }

    state "wait2"
    {
        if(timeout(8.0))
            state = "done";
    }

    state "done"
    {
        Console.print("You're done!");
        Application.exit();
    }
}

Link: https://github.com/alemart/surgescript/ … timeout.ss

Re: Introducing surgescript

Sorting in SurgeScript

One of the most important themes in computer science is sorting. In games, you may use sorting, for example, to create a high scores table and display the highest scores first. SurgeScript allows you to sort arrays using the sort() method: smile

Original array:
3 7 1 5 9 2 4 6 8 0
Sorting in ascending order...
0 1 2 3 4 5 6 7 8 9
Sorting in descending order...
9 8 7 6 5 4 3 2 1 0
Sorting in custom order (odds first)...
1 3 5 7 9 0 2 4 6 8

You can sort anything: numbers, strings and even more complex data.

Code link: sort_array.ss

Re: Introducing surgescript

I can see that the development of SurgeScript does not stop. The progress is awesome. Having such tool as the scripting engine inside Open Surge is going to make it really powerful.

When will be integrated?

Piece of cake...!

Re: Introducing surgescript

TheSeventhEmerald wrote:

When will be integrated?

It's about to be integrated. One or two details to do, and the first build of SurgeScript will be done. Then comes the integration.

Re: Introducing surgescript

Can't wait to see this program released smile

It will be awesome to make games of all genres on an easy way!

Re: Introducing surgescript

Advanced features

A very nice feature of object-oriented programming languages is called a functor (or function object). It allows you to have objects that behave like functions.

In SurgeScript, you can do really powerful programming using functors. In the example below, we have an object called Benchmark that can measure the performance of any code/object that you provide:

// We'll measure the performance of the computation of the Fibonacci sequence using an exponential method
object "Application"
{
    benchmark = spawn("Benchmark");
    fib = spawn("Fibonacci");

    state "main"
    {
        t  = benchmark(fib(1));
        t += benchmark(fib(5));
        t += benchmark(fib(10));
        t += benchmark(fib(25));
        t += benchmark(fib(32));
        Console.print("Total time: " + t + " seconds.");
        Application.exit();
    }
}

In my computer, the output of this program is as follows:

Computing ExpFib(1) = 1          done in 0.000018 seconds.
Computing ExpFib(5) = 5          done in 0.000052 seconds.
Computing ExpFib(10) = 55          done in 0.000478 seconds.
Computing ExpFib(25) = 75025          done in 0.203170 seconds.
Computing ExpFib(32) = 2178309          done in 5.642050 seconds.
Total time: 5.845768 seconds.

Check out the full example!

Granted, it's an advanced feature. smile

Re: Introducing surgescript

Advanced features

Is this script necessary for levels with a large map and a large number of objects?
I think It can be tested in a virtual machine with Windows 98 or 2000.

Re: Introducing surgescript

G.E.R. wrote:

Is this script necessary for levels with a large map and a large number of objects?
I think It can be tested in a virtual machine with Windows 98 or 2000.

I don't think so. Open Surge runs well even in old computers, and once the map is loaded you should have no problem. It is more useful to test algorithms inside the new SurgeScript.

Alexandre wrote:

Advanced features
A very nice feature of object-oriented programming languages is called a functor (or function object). It allows you to have objects that behave like functions.

In SurgeScript, you can do really powerful programming using functors. In the example below, we have an object called Benchmark that can measure the performance of any code/object that you provide

Granted, it's an advanced feature.

Nice addition. My only criticism is that the functor has not a very clear syntax. At least for me it is diffiicult to understand, only reading the code, what is exactly the black magic behind it. In C++ for example the functor is done overloading (), which is way easier to understand. However, it may be matter to get used to it.

I see that the scripting is getting really complete. I think it is time to integrate it with the Open Surge engine to test it in the wild. I really want to get my hands dirty with it.

Happy new year to everybody, BTW.

Last edited by TheSeventhEmerald (2018-01-05 10:01:58)

Piece of cake...!

Re: Introducing surgescript

I'm sorry for butting in on the conversation (this should be in another section but...), Is it possible to set a custom fps for a Sprite via objects?

If it's not, that's ok, but I want to know if it's possible to do so. I want to play around with certain time variables and I want it to include sprite fps.

(I sped read the whole thing because I'm on time constraints right now, so if it's already an asked question I understand.)

www.facebook.com/24XFSAL  Hasn't been updated anytime recently, don't bother.
I'm on SoundCloud: https://soundcloud.com/rain-new-holy - I plan to upload one soon.
Name change from 24XFSAL coming soon. Currently studying for Information Technology and Game development. (Also studying game theory in spare time.)

Re: Introducing surgescript

aronthehedgehog wrote:

I'm sorry for butting in on the conversation (this should be in another section but...), Is it possible to set a custom fps for a Sprite via objects?

If it's not, that's ok, but I want to know if it's possible to do so. I want to play around with certain time variables and I want it to include sprite fps.

(I sped read the whole thing because I'm on time constraints right now, so if it's already an asked question I understand.)

Hi aronthehedgehog, welcome back. smile

set_animation_speed_factor

Re: Introducing surgescript

Alexandre wrote:
aronthehedgehog wrote:

I'm sorry for butting in on the conversation (this should be in another section but...), Is it possible to set a custom fps for a Sprite via objects?

If it's not, that's ok, but I want to know if it's possible to do so. I want to play around with certain time variables and I want it to include sprite fps.

(I sped read the whole thing because I'm on time constraints right now, so if it's already an asked question I understand.)

Hi aronthehedgehog, welcome back. smile

set_animation_speed_factor

Ok, thanks!
This'll greatly help me.

www.facebook.com/24XFSAL  Hasn't been updated anytime recently, don't bother.
I'm on SoundCloud: https://soundcloud.com/rain-new-holy - I plan to upload one soon.
Name change from 24XFSAL coming soon. Currently studying for Information Technology and Game development. (Also studying game theory in spare time.)