Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   GS2 Emulator (https://forums.graalonline.com/forums/showthread.php?t=134265855)

fowlplay4 02-27-2012 06:47 PM

GS2 Emulator
 
We're all aware of the issue regarding being unable to test GS2 without NC, and that GS2 is very similar to JavaScript. It's similar enough with a little bit of replacing that I could get a bunch of basic output scripts to run.

So in order to help newbies get into GS2 and complete the first few (5) parts and first challenge of my tutorial I have created a basic emulator.

This is currently just a learning tool to allow newbies to get their feet wet, anyone who wants to further develop it is welcome to. There's still plenty to do. I.e. Simulated Client-Side/Server-Side functionality (and triggerserver/triggerclient), proper temp prefix functionality, GS2 to JS array conversion, numerous global functions.

Notes:
  • Concatenation symbols (@, SPC, NL, TAB) are replaced with their javascript equivalent.
  • All variables are global so the temp prefix will not work the same way as it does in GS2.
  • Arrays and a vast majority of other functions are currently not emulated. If you want to use array's use [ and ] instead of { } when defining them.

Enjoy.

Link: http://fp4.ca/gs2emulator/
Tutorial: http://public.zodiacdev.com/index.php?title=Fowlplay4

Cubical 02-27-2012 07:19 PM

I'm attempting to test it on my phone. This isn't working for me

function onCreated() {
temp.I =0;
Temp.t = { "Paul", "frank", "Sam"};
For(temp.I=0; temp.I<temp.t.size();temp.I++){
Echo(temp.t[temp.I]);
}
}

Cubical 02-27-2012 07:22 PM

Attempted using [ and ] for the array

Cubical 02-27-2012 07:26 PM

This forest work either
function onCreated() {
Temp.t = [ "Paul", "frank", "Sam"];
For(temp.I : temp.t){
Echo(temp.I);
}
}

fowlplay4 02-27-2012 07:36 PM

Anything array-based really doesn't work at all unless you know how arrays work in JS.

The temp is case-sensitive, and it's length not size() in JS. What does work is:

PHP Code:

function onCreated() {
  
temp.= ["Paul""frank""Sam"];
  for (
temp.I=0temp.temp.t.lengthtemp.I++){
    echo(
temp.t[temp.I]);
  }


The only GS2 function that is currently implemented is echo().

Keep in mind this emulator is still very much a work-in-progress.

Tolnaftate2004 02-27-2012 07:39 PM

JavaScript uses for (member in object) { ... } which is like for (member: object.getvarnames()) { ... }. That's probably why it's not working.

e: Good lord is this a horror.

e2: Array.prototype.size = function () { return this.length; }. Do it.

fowlplay4 02-27-2012 08:02 PM

Cleaned up the source code a little bit, added size since it was right there.

gs2_setup() - Implements some GS2-like functionality.
gs2_script() - Does some small conversions.
gs2_emulate() - Calls setup, clears output, gets script, and evals it as JS.

So if you want to add to it go for it.

This also works now but I would suggest not trying to script on your phone.

PHP Code:

function onCreated() {
  
temp.=0;
  
temp.= ["Paul""frank""Sam"];
  for (
temp.I=0temp.temp.t.size(); temp.I++){
    echo(
temp.t[temp.I]);
  }



Cubical 02-27-2012 08:21 PM

I was just testing it on my phone. I wouldn't normally use uppercase letters when defining a variable it was just the auto correct on my phone. If I had known it would make a difference I would have changed it.this thing is still pretty nifty

smirt362 02-27-2012 09:13 PM

Neato!

Hezzy002 02-27-2012 09:16 PM

Quite the hack, but I guess it's better than nothing.

Crono 02-27-2012 09:35 PM

oh graal players, always doing the dirty work "they" should have done ages ago

Tricxta 02-27-2012 09:59 PM

I spose you're still yet to implement for each loops?

fowlplay4 02-27-2012 10:09 PM

Quote:

Originally Posted by Tricxta (Post 1686216)
implemented for each loops?

They are not, need arrays properly converted before that will happen.

Hezzy002 02-27-2012 10:24 PM

I really wish you never did this. It's never going to get anywhere because it's a weird Javascript parser and preprocessor step rather than an actual VM or even interpreter, yet people in the future will point back to it and go, "Look, it exists! Now shut up." There are so many reasons why this is a bad idea.

Crono 02-27-2012 10:27 PM

Quote:

Originally Posted by Hezzy002 (Post 1686221)
I really wish you never did this. It's never going to get anywhere because it's a weird Javascript parser and preprocessor step rather than an actual VM or even interpreter, yet people in the future will point back to it and go, "Look, it exists! Now shut up." There are so many reasons why this is a bad idea.

Sure is better than nothing for newbies who want to learn.


All times are GMT +2. The time now is 03:30 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.