Skip to main content

News

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Radnen

1411
Site Comments / Re: Spherical Forums

Re wiki link - once I get crackin' on theming, link will return!

Re "user is online" box - I don't rightly know yet where that toggle is on SMF v2, but when I find it I'll turn it on.


I swear it was on a few days ago. I remember seeing it when I was replying to Jester in his topic.
1412
Oh wow! That does look nice.
1413
Resources / Re: [code] Object Serialization

Code: [Select]

var f = new Function("return new " + o.zztype + "();");
var obj = f();


Seems like it should just be

Code: [Select]

var obj = global[o.zztype]();



That's quite nifty!

Edit: It doesn't work in Sphere. 'global' is not defined. I did some digging and found that the only way to access the global scope is by calling 'this' while in the global scope. So I changed the code to:

Code: [Select]

var obj = new this[o.zztype]();


It can be still a little dangerous if the environment does have that object in the global scope, I'll have to add a small check there first. And you are right about cyclic structures, but I don't use them often, and they aren't usually used for the kind of data that is intended to be saved, even though there might possibly a reason somewhere down the line.


Are you planning some sort of binary format, for instance to make save files harder to modify?


Not really, my plan was to add an encode/decode layer to the final output string/bytearray.
1414
Engine Development / Re: TurboSphere
In Windows, GetFileList returns an empty object.
1415
Engine Development / Re: TurboSphere

On another note, I think that there is builtin JSON in V8 by default, so you shouldn't need the json.js files (but don't quote me on that).


I don't know.. I couldn't get foreach to work... and it was implemented in JS 1.6... I'm still using my foreach code! But we'll see... It's still good to have.

I got radgui to now work!

That means, I have now got radlib's debug system working (the interactive version, supplied by radgui). Yay, I can finally report errors! But there were many things it's lacking.

1. Surface.gradientRectangle()
2. Font.getHeight();
3. Accurate Font.getStringWidth()
4. Font/WindowStyle .get/.setColorMask()
5. Image.blitMask()
6. GetFileList()
7. GetDirectoryList()
8. GetNumJoystickButtons,
9. IsMapEngineRunning,
10. Font.wordWrapString(),
11. Windowstyles are not drawing their backgrounds?
12. Fot.drawTextBox()
13. JS Error (Esp error.stack)

Re the "result will be passed": It seems to be the last function/line in the file.

Code: [Select]

Opening script startup/scripts/radlib/hooklist.js
File is good.
JS Result will be passed.
function (key) {
        var hook = List.get(this.hooks, key, "key");
        hook.paused = false;
}


Equals:
Code: [Select]

HookList.prototype.unpause = function(key) {
var hook = List.get(this.hooks, key, "key");
hook.paused = false;
}
1416
Engine Development / Re: TurboSphere

I'm trying to make it more like Sphere had it, without just turning RequireScript into a C-style include that will just dump the second script into the first. There surely are elegant solutions working just with V8. But I don't know exactly how to do that yet.


No kidding, line error's are in the 1000's!

I don't know if this is a bug or feature, but you've made Sphere Objects [object Object] types rather than [object Image] etc. which Sphere did. So, it's harder to tell if an image is an image or some object.

Edit: Now I'm running into an issue with the console. I don't see the entire log. I'm loading hundreds of scripts, okay, so the console has a huge list of stuff, but only stops half-way before the screen pops up running. Then when an error occurs, nothing else is added to the console.

Code: [Select]

$ ./turbosphere.exe
Fixed plugins: 1
Fixed plugins as recorded: 1
Opening SGM file startup/game.sgm
Opening script startup/scripts/main.js
File is good.
Opening script startup/scripts/radlib/radlib.js
File is good.
Opening script startup/scripts/radlib/radextend.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/animation.js
File is good.
JS Result will be passed.
function (x, y) {
        this.frames[this.frame].i.blitMask(x, y, this.color);
}
Opening script startup/scripts/radlib/assert.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/audio.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/colors.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/debug.js
File is good.
Opening script startup/scripts/radlib/game.js
File is good.
Opening script startup/scripts/radlib/hooklist.js
File is good.
JS Result will be passed.
function (key) {
        var hook = List.get(this.hooks, key, "key");
        hook.paused = false;
}
No JS result will be passed
No JS result will be passed
Opening script startup/scripts/radlib/event.js
File is good.
JS Result will be passed.
function () {
        return this.parent.constructor.name;
}
Opening script startup/scripts/radlib/game.js
File is good.
Opening script startup/scripts/radlib/hooklist.js
File is good.
JS Result will be passed.
function (key) {
        var hook = List.get(this.hooks, key, "key");
        hook.paused = false;
}
No JS result will be passed
Opening script startup/scripts/radlib/hooklist.js
File is good.
JS Result will be passed.
function (key) {
        var hook = List.get(this.hooks, key, "key");
        hook.paused = false;
}
Opening script startup/scripts/radlib/inherit.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/input.js
File is good.
JS Result will be passed.
function (button) {
        return IsJoystickButtonPressed(this.num, button);
}
Opening script startup/scripts/radlib/image.js
File is good.
JS Result will be passed.
function (x1, y1, radimg, x2, y2) {
        // setup positions:
        var top    = Math.max(y1, y2);
        var left   = Math.max(x1, x2);
        var right  = Math.min(x1 + this.width , x2 + radimg.width )-1;
        var bottom = Math.min(y1 + this.height, y2 + radimg.height)-1;

        // collision:
        var colA, colB;
        for (var y = top; y < bottom; ++y) {
                for (var x = left; x < right; ++x)
                {
                        colA = this.canvas.getPixel(x - x1, y - y1);
                        colB = radimg.canvas.getPixel(x - x2, y - y2);
                        if (colA.alpha > 0 && colB.alpha > 0) return true;
                }
        }

        return false;
}
Opening script startup/scripts/radlib/json2.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/list.js
File is good.
Opening script startup/scripts/radlib/assert.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/debug.js
File is good.
Opening script startup/scripts/radlib/game.js
File is good.
Opening script startup/scripts/radlib/hooklist.js
File is good.
JS Result will be passed.
function (key) {
        var hook = List.get(this.hooks, key, "key");
        hook.paused = false;
}
No JS result will be passed
No JS result will be passed
No JS result will be passed
Opening script startup/scripts/radlib/loader.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/mouse.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/path.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/resources.js
File is good.
No JS result will be passed
Opening script startup/scripts/radlib/savefile.js
File is good.
Opening script startup/scripts/radlib/json2.js
File is good.
No JS result will be passed
JS Result will be passed.
function (filename) {
        if (!Assert.is(filename, "string")) { Debug.log("Filename not a string.", LIB_ERROR); return; }

        if (filename.indexOf(".") < 0) filename += ".sav";

        if (!Assert.fileExists("~/other/", filename)) {
                Debug.log(FormatString("File {?} doesn't exist!", filename), LIB_ERROR);
                return;
        }

        var file = OpenRawFile("~/other/" + filename);
        this.content = JSON.parse(CreateStrin



Edit2: Only when there's a script error hmm... Weird.
1417
Engine Development / Re: TurboSphere
Well, it just closes. It's a CTD type of crash, and it does not generate an output file. I put "breaks" (GetKey()) around the code I'm trying to test, but even then it will CTD between two code statements, especially stuff in other code files.
1418
Engine Development / Re: TurboSphere
I was able to get the core radlib library to run under TS, but many of the more complicated features can't run. And I cannot fix them since it crashes straight-away without telling me why. For example, a simple syntax error will make it crash, or a function that wasn't defined. It's hard to debug this way.
1419
Game Development / Re: The Screenshot Thread
yes, yes, YES! Joystick support is nice to have.
1420
Resources / [code] Object Serialization
This piece of code is from my radlib library, but I'm putting it here because others might benefit from having this in their game, whether or not they want the full RadLib library.

These two functions, Serialize and Deserialize will store/recall JS objects, restoring their prototypes and non-serializable sphere objects. In Serialize, a new property is tacked on to an object: "zztype", it stores the constructor of the object that created it. Deserialize will call that constructor and then proceed to fill in the stored fields. The reason for this is twofold, one, when the object is re-created it becomes an object of the type of it's constructor rather than 'object' (JSON stringify/parse will turn all objects into general JS objects and strip the methods off of them), two, any sphere objects such as images will be reattached since usually they are created in the constructor function and since they are only used for display: we don't tend to store images/fonts/windowstyles, so they don't have to be saved.

Both Serialize and Deserialize do a deep inspection/clone, so nested objects are also affected.

Code: (javascript) [Select]

/**
* Serialize(obj : object);
*  - Use this to JSON an object; AND preserve the data type.
**/
function Serialize(obj)
{
function Make(obj) {
var o = { zztype: obj.constructor.name };
for (var i in obj) {
if (!(obj[i] instanceof Array) && typeof obj[i] == "object")
o[i] = Make(obj[i]);
else
o[i] = obj[i];
}
return o;
}

return JSON.stringify(Make(obj));
}

/**
* Deserialize(s : string);
*  - Use this to parse a JSON object; AND restore the methods.
**/
function Deserialize(s)
{
function Make(o) {
var obj = new this[o.zztype]();
for (var i in o) {
if (!(o[i] instanceof Array) && o[i] typeof "object")
obj[i] = Make(o[i]);
else
obj[i] = o[i];
}
delete obj.zztype;
return obj;
}

return Make(JSON.parse(s));
}


Therefore, you can now make a class like so:

Code: (javascript) [Select]

function Item() {
  this.image = LoadImage("dagger.png"); // an image... which can't be saved to file...
  this.damage = 5; // this however can; even with JSON.
}

// but this method will be stripped during JSON creation
Item.prototype.swing = function() {
  Print("Did " + this.damage + " damage!");
}

var item = new Item();
item.damage += 2; // I upgraded it!!

// serialization keeps an object, well the same object!
var s = Serialize(item);
File.save("item", s); // now I saved it to file!

var o = File.recall("item", "");
item = Deserialize(o);

item.swing(); // prints "Did 7 damage!"
item instanceof Item // returns true


This is great for games where the inventory changes and the items must each be saved. Or other properties such as player stats, and world variables, etc. Have fun!

(edited for proper highlighting ~neo)
1421
Engine Development / Re: TurboSphere
Amazing work! Just to let you know, I'm building up a unit test framework for testing all kinds of things in your engine.
1422
Engine Development / Re: TurboSphere
I'm going to use github to post any issues I find with it, so check there periodically. I'm going to try and experiment and use turbosphere. So, basically I'm going to beta test it's features!
1423
Spherical News / Re: **READ ME FIRST
I edited your post to clarify the reason for verified vs non-verified. Perhaps one day the message can be further edited to include more or less a comprehensive list of various forum rules (but there doesn't have to be any if we feel like it).
1424
Engine Development / Re: TurboSphere
Do you have an API list anywhere? I'm curious to see how much you have implemented. And if I could perhaps get started with making some kind of game... I don't need sound right now, but I hope there's enough to create something interactive.
1425
Spherical News / Re: **READ ME FIRST

Alright. If there's no issue on the forums yet, I suggest not to put up that big registration barrier with manual verification.


It was only supposed to be temporary until NEO adds the necessary safety procedures. So I don't think this will last much longer, unless there were complications?