S Plugin...Reliable???

For questions about using Classic.

Post » Sat Apr 02, 2011 4:41 am

Everything in 's' is an array per definition. So there are two ways:

1) Just use a 1-dimensional number array and access it with math.
[list:33crb1fi] 's' is 0-based. If your map is 1-based, then you get the right field of the array by calculating:

(mapY - 1) * mapWidth + (mapX - 1)

map size: 32x20
map position: 5, 4
resulting position: (4-1)*32 + (5-1) = 100[/list:u:33crb1fi]

2) Make a super which holds a number array (create it using template)
[list:33crb1fi]The super is an array and the number array also. Let's say the super is called 'X' and the number array 'Y'. Then you could (0-based) access it as if it were a 2d array:
{"X", 4, "Y", 3}[/list:u:33crb1fi]
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Apr 02, 2011 7:37 am

[quote="tulamide":1acwz8dw]2) Make a super which holds a number array (create it using template)

The super is an array and the number array also. Let's say the super is called 'X' and the number array 'Y'. Then you could (0-based) access it as if it were a 2d array:
{"X", 4, "Y", 3}[/quote:1acwz8dw]

This seems like a rather odd way to use S, to me at least. I'd propose a level hierarchy similar to the following:

[code:1acwz8dw]Levelpack (Super)
|
Level (Super)
| | | |
| Title (String) Xsize (Number) Ysize (Number)
|
Tiles (Super)
| | |
Xpos (Number) Ypos (Number) Frame (Number)[/code:1acwz8dw]

Setting up templates for your supers. So you can just add a Super for each Tile/Enemy/whatever and it has all the subarrays needed. And yeah, this uses many arrays with only one value actually stored, so it's more like a single variable.

{"Levelpack","Level",2,"Tiles",14,"Frame"} would be the frame of the 14th tile stored in level 2 for example, just to show a bit with an actual S address. To create your level you would of course use the loop conditions of S and spawn objects accordingly.

I do know that S can save objects directly with a spatial info array, but I do prefer to do it with templates holding all the necessary info in any case.

Seems to be like experiences and methods using S can end up being quite different, consider this only my 2 cents.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Sat Apr 02, 2011 7:47 am

[quote="PixelRebirth":1iwrkt9y]This seems like a rather odd way to use S, to me at least. [/quote:1iwrkt9y]
It is not the way I use 's'. Just have a look at the music tool I started some time ago.

It was just a practical approach of recreating a non-object-oriented 2D array with the object oriented 's' plugin. :wink:
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Apr 02, 2011 9:24 am

[quote="KrushBrother":2s8hmqz2]
In other words, I want to use S like a standard 2d array for the level data,[/quote:2s8hmqz2]
edit: just realized tulamide's #2 method was what I was going to say was the closest thing to a 2d array, but
There's probably an easier way to do what you're thinking, what're you going to use the 2d array for?
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sat Apr 09, 2011 9:12 pm

Sorry for the late response, but I've been stupidly busy.
Thanks for the input guys.
Helpful as ever.

I've made 2 versions of the editor, one using the spatial info, and another using an array to keep all the level info I need, and I'm writing the level loading routines to use either, so I can decide which I'm happier with.

I just need some spare time at the moment to get back into it.

Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

Post » Tue Apr 19, 2011 9:54 am

Ok, here's one for you. :D

For this project, I've decided to stick with a normal array object rather than using S, mainly because of the amount of work I'd already put into the editor.

But I would still like to utilise S to pack up my level data.

So here's the question;
If I have several array objects with the level data in them, is it possible to use S to save them into an encrypted file, so that when the level pack is loaded using S, the arrays are filled with the data that they were when saved?

My initial tests seem to suggest that the array data is not saved with the object.
If this is the case, is there a chance of an update that could allow this. :wink:

Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

Post » Tue Apr 19, 2011 12:15 pm

hey, krush
this is correct. The object arrays only have pointers to the objects, it doesn't save an actual object. If you were to take a text object and rename it "Sprite", and a "Sprite" was in an array you loaded, it would load that. So, although there are some handy tricks like the Spacial Info Array actions to put all your objects exactly as you left them. Object specific things can't be saved. As far as an update that can change this. I'm not sure it's even possible, but definitely outside the scope of my programming ability. The only thing I can foresee adding to the save ability is private variables, but I don't plan on working in depth on 's' to add new features until after I'm done with my current long term project. Though I will fix bugs.

That being said, what you're trying to do is actually very simple to pull off. In this example it'll be like you renamed your regular Construct array to ArrayObject, to avoid confusion as you read this
When you go to save: Say you press F1 to save:
[quote:15wihy99]
Mouse Keyboard : On key F1 pressed
----S: Create Number Array (or string array if necessary) "MyArraySave"

----ArrayObject : For Each Element:
----------S.Insert Number : ArrayObject.CurrentValue at "end" of "MyArraySave"

----Always:
----------S.Save Super {""} : Encrypted
----------S.Delete Array "MyArraySave"[/quote:15wihy99]


And just do the reverse to load it. Load the s super
for each number in "MyArraySave", add that data to the standard construct array
and then delete the s array
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Tue Apr 19, 2011 1:05 pm

lucid did beat me to it, but I made such a nice example (although a little more complex), well commented and such, so I will post the link anyway ;)

using_s_to_save.cap
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Apr 19, 2011 2:26 pm

Once again, I salute you guys. :D

My array has now become a 3D array with the development of the game, but that's easy enough to sort.

This technique will allow me to package up everything I need for packs of 25 levels, complete with pack-specific custom spritesheets, etc.
Nice!

Thanks guys.

Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests