Open Surge Forum

A fun 2D retro platformer inspired by Sonic games and a game creation system

You are not logged in.

Announcement

Our community has moved to Discord! https://discord.gg/w8JqM7m

#1 2018-05-06 01:52:41

lainz
Member
Registered: 2009-02-18
Posts: 202

Making a website with SurgeScript

I'm making websites with SurgeScript.. smile

In a .bat file (Windows only) put this:
surgescript.exe web.ss > web.html

This is the web.ss:

object "Application"
{
    state "main"
    {
        Console.print('<!DOCTYPE HTML>');
        Console.print('<html>');
        Console.print('<head>');
        Console.print('<title>Hello World from SurgeScript</title>');
        Console.print('</head>');
        Console.print('<body>');
        Console.print('<p>Hello <b>World</b>!</p>');
        Console.print('</body>');
        Console.print('</html>');
        Application.exit();
    }
}

And this is your website:
Hello World!

I'm missing how to start a local server, but that can be done with several tools, I'm running it with VS Code 'Live Server' plugin. Or you can double click the file...

Offline

#2 2018-05-12 02:32:34

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,300
Website

Re: Making a website with SurgeScript

I never thought of it, but creating a website with SurgeScript might indeed be possible smile

You can have your .bat file call SurgeScript to serve a web page. You can also pass command line arguments to your script, so you can receive some input. Link your .bat to a web server (use CGI or something) and voilá, you have the first website ever written in SurgeScript served to the web smile

Offline

#3 2018-05-12 17:04:01

lainz
Member
Registered: 2009-02-18
Posts: 202

Re: Making a website with SurgeScript

Yes, it's an idea.

I don't have currently access to a CGI server, but I can try locally.

The thing that diferentiates a language from the rest, is not just the intrinsic language features, but all the libraries available to use.

For that, I asked about having an 'import' clause, instead of feeding the executable with all sources one by one. So libraries can be distributed anywhere, and you need to just import them, or put them in the surgescript 'path'.

Offline

#4 2018-05-12 18:50:08

lainz
Member
Registered: 2009-02-18
Posts: 202

Re: Making a website with SurgeScript

But don't worry adding import, it was just a sugerence, is not needed for the game, better focus on the main goal, that's using it with the game engine.

I can run a bat and add all the files with no problem wink

Offline

#5 2018-05-12 21:32:19

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,300
Website

Re: Making a website with SurgeScript

Regarding the game, I would like that users have the ability to just put their scripts on a folder like scripts/ and let the game just work without any issues.

But I'll think about it.

Suppose that you have a single instance of an object, say, SceneManager, and that you need to use it frequently in the game. How would you import it into your script?

Offline

#6 2018-05-13 02:25:53

lainz
Member
Registered: 2009-02-18
Posts: 202

Re: Making a website with SurgeScript

Alexandre wrote:

Regarding the game, I would like that users have the ability to just put their scripts on a folder like scripts/ and let the game just work without any issues.

Yes, is the best.

Alexandre wrote:

Suppose that you have a single instance of an object, say, SceneManager, and that you need to use it frequently in the game. How would you import it into your script?

What you are saying is a global variable, or static methods, or a mix of both.

With global variable, if the unit is in the imports section, that variable is available for that unit and objects inside.

like

// in scenemanager.ss, somewhere
GlobalSceneManager = spawn(SceneManager);

import 'scenemanager.ss'

GlobalSceneManager.doSomething() //.. call of the global variable, the advantage on this is that the state is stored in the global, and any unit that imports it can access (read, write) the state of this global

With static methods, if the unit is in the imports section, the class methods are available with no need to instantiate them.

import 'scenemanager.ss'

object SceneManager {
  hello_string_never_recheable_from_static_methods (variable visible only for an instance)
  static hello_static_string (global variable inside a class, visible outside)
  static fun doSomething...
}

SceneManager.doSomething() //.. with no need to instantiate

What I know, is that static methods only uses the data inside of them, and also static fields. But they don't have a 'state' of the normal fields.

So you can implement globals or static class methods.

Or something better, like an object that's global

global object SceneManager {

}

it can be instantiated automatically by the engine, or instantiated only the first time by the code

The name of the object is SceneManager, and you call it like SceneManager.doSomething()..

Offline

Board footer

Powered by FluxBB  hosted by tuxfamily.org