[ian-reeds-games] Dev 41: A fix for Craig's scripts, hopefully

  • From: Ian Reed <support@xxxxxxxxxxxxxxxxxxx>
  • To: ian-reeds-games@xxxxxxxxxxxxx
  • Date: Sun, 03 Nov 2013 11:31:35 -0700

I've released dev 41.
Be wary of trying it unless you want to help me find the bugs.
I haven't tested with Craig's scripts directly since I don't have test cases for that so I appreciate anyone who wants to check if this fixes them.

Craig, I did find the problem with setting variables on the global object and it should be fixed now. If it wasn't broken in dev 38 and 39 I'm surprised because I don't think that code changed in dev 40.

In dev 38 I changed how the global object works.
It used to be an actual javascript object, but now it is a C# object.

There are 3 things you should know about:
1 The scripter storage stuff is no longer necessary.
Because it is a C# object you can store actual C# types on it like Units, Skills or Items and they will get saved and loaded properly.
That is the main reason I made this change.

2 If you set a javascript object on the global object it will change it into a C# object.
This means that you'll want to get a new reference to that object.
So this code does not work:
var cr = new Object();
global.craig_brett = cr;
// at this point cr is still a javascript object and global.craig_brett is a C# object.
On the other hand this code does work:
global.craig_brett = new Object();
var cr = global.craig_brett;
// both cr and global.craig_brett point to the same C# object.

I've done this because javascript objects can not be shared between javascript and C# and always get copied by value when they cross the language boundary. So the best I can do is turn the copied by value object into a C# object that can be shared after that point.

3 for (var prop in object) continues to not work on the C# objects and arrays. This has not changed but since you were storing javascript arrays and objects on the global object you may have previously been using this form of iteration on them which would be broken now since they are converted to C# objects.

Sorry for the changes, but I think it's better off since it gets rid of the confusing scripter storage stuff.

Ian Reed


Other related posts: