Pages: 1 2 »
  Print  
Author Topic: Who fixed arrays?  (Read 4545 times)
Offline (Male) Goombert
Posted on: October 10, 2014, 02:42:33 AM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
I was going to do a little something, and realized that arrays were fixed. I can't quite recall who or what fixed them or when they did it, but they do seem to work now.

The following builds fine for me on the latest master.
Code: (EDL) [Select]
var ass;
ass[0] = 69;

show_message(string(ass[0]));

Whoever it was, thank you!

Additionally that thing I was trying to do was provide an array length function, but sadly JDI fails to parse the templates, it keeps saying the function is undefined unless I change the parameter
Code: (C++) [Select]
  template <unsigned array_size>
  unsigned array_length_1d(variant (&v)[array_size]);
« Last Edit: October 10, 2014, 02:45:39 AM by Robert B Colton » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) egofree
Reply #1 Posted on: October 10, 2014, 03:46:29 AM
Contributor
Joined: Jun 2013
Posts: 603

View Profile Email
I think nobody fixed the arrays. It was always possible to declare arrays with var. The problem is that it's possible to use arrays only with var type. Currently it's not possible to declare strongly type arrays.

In the past i updated already the wiki :

Quote
Arrays

An array is always declared as a variant data type with the keyword var, followed by its name.

http://enigma-dev.org/docs/Wiki/ENIGMA:Specification
« Last Edit: October 10, 2014, 04:08:11 AM by egofree » Logged
Offline (Unknown gender) sorlok_reaves
Reply #2 Posted on: October 10, 2014, 06:13:43 PM
Contributor
Joined: Dec 2013
Posts: 261

View Profile
Arrays are not, I think, entirely fixed. The way they're copied and garbage collected seems a bit off to me (I'm also debugging array-based problems in Spelunky).

But, yes, basic array usage works just dandy.
Logged
Offline (Male) Goombert
Reply #3 Posted on: October 10, 2014, 06:31:25 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
Do you have any ideas on implementing array length sorlok? I was wanting to add some like sprite_getpixels and surface_getpixels or even d3d_model_vertices(var vertices[]) functions that return an array to avoid multiple bindings for each pixel. Without JDI supporting collections in EDL yet and me not wanting the functions to rely on the data structure extension, we are left with returning arrays. But they are unusable if the user can not get the array dimensions with the Studio function.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) Darkstar2
Reply #4 Posted on: October 10, 2014, 06:36:44 PM
Member
Joined: Jan 2014
Posts: 1244

View Profile Email
I never knew arrays were broken they always worked for me.  :D
Logged
Offline (Unknown gender) sorlok_reaves
Reply #5 Posted on: October 10, 2014, 08:15:38 PM
Contributor
Joined: Dec 2013
Posts: 261

View Profile
Do you have any ideas on implementing array length sorlok? I was wanting to add some like sprite_getpixels and surface_getpixels or even d3d_model_vertices(var vertices[]) functions that return an array to avoid multiple bindings for each pixel. Without JDI supporting collections in EDL yet and me not wanting the functions to rely on the data structure extension, we are left with returning arrays. But they are unusable if the user can not get the array dimensions with the Studio function.

I can probably figure it out. I'd like to remove the "placement new" that Josh put in first, because it I find it confusing (and he said I could). At that point, it's just a matter of fiddling around with the lua_table struct. So, yep, I'll give it a shot.


I never knew arrays were broken they always worked for me.  :D

Another satisfied customer! :D
Logged
Offline (Male) Goombert
Reply #6 Posted on: October 10, 2014, 08:27:52 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
Quote
Another satisfied customer! :D
If I had the authority, I'd double your salary sorlok. If you could fix arrays and give me the array length, I would be very happy and implement a lot of powerful functions that would completely remove the need for even dealing with buffers to read surfaces, I honestly don't know why YYG always has to overcomplicate things too.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) Darkstar2
Reply #7 Posted on: October 10, 2014, 08:33:45 PM
Member
Joined: Jan 2014
Posts: 1244

View Profile Email
I honestly don't know why YYG always has to overcomplicate things too.

Well if that were not the case maybe ENIGMA would never have been born :D

@Sorlok: You hear that ? Double the salary, now that is something you cannot resist :D

Logged
Offline (Unknown gender) TheExDeus
Reply #8 Posted on: October 12, 2014, 07:52:11 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
Var arrays have always worked as far as I know. Like this:
Code: [Select]
var arr;
arr[0] = 69;
Or just this:
Code: [Select]
arr[255] = 69;
What hasn't worked is this:
Code: [Select]
local int arr[256];
arr[2] = 10;
And that is been a problem for a few years for me, as data structures and var arrays are A LOT slower than a regular C++ array. Another thing we could do is implement STL containers. But for that we need access to classes, which sadly don't work. I'm still waiting on that new parser Josh.... though seeing how the old one is band-aided all the time, it seems the development on the new one has slowed.
Logged
Offline (Unknown gender) Darkstar2
Reply #9 Posted on: October 12, 2014, 09:17:50 AM
Member
Joined: Jan 2014
Posts: 1244

View Profile Email
Oh ok thanks for refreshing my memory Harri, indeed....I am used to the C++ arrays, I remembered we could not use those in ENIGMA sadly.....  Imagine if we could though, would this require a massive change ?  Sorlok ???

Logged
Offline (Unknown gender) sorlok_reaves
Reply #10 Posted on: October 13, 2014, 12:19:46 PM
Contributor
Joined: Dec 2013
Posts: 261

View Profile
Oh ok thanks for refreshing my memory Harri, indeed....I am used to the C++ arrays, I remembered we could not use those in ENIGMA sadly.....  Imagine if we could though, would this require a massive change ?  Sorlok ???

For now I'm looking into the array length questions.

Local primitive arrays shouldn't be too difficult, but reclaiming the memory when it becomes unused is a little trickier.

Does GM:S offer "local int arr[255]"? I'm not familiar with the syntax, but then again most of my work is with GM 5.
Logged
Offline (Unknown gender) TheExDeus
Reply #11 Posted on: October 13, 2014, 01:33:59 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
No, GM doesn't have any types. ENIGMA has types. To create a local variable with a type you have to have "local" in front of it. So this:
Code: (EDL) [Select]
a = 10; //This is variant local for the instance
var a = 10; //This is temporary variant for the script
int a = 10; //This is a temporary integer for the script
local int a = 10; //This is an integer local for the instance
Logged
Offline (Unknown gender) egofree
Reply #12 Posted on: October 13, 2014, 02:21:19 PM
Contributor
Joined: Jun 2013
Posts: 603

View Profile Email
No, GM doesn't have any types.

In fact i forgot this ! :D This means arrays don't need fixing, still it would be cool to add length functions, even if it's not mandatory.
Logged
Offline (Unknown gender) sorlok_reaves
Reply #13 Posted on: October 14, 2014, 09:13:14 AM
Contributor
Joined: Dec 2013
Posts: 261

View Profile
I've got a work-in-progress for array lengths:
https://github.com/sorlok/enigma-dev/compare/enigma-dev:master...sorlok:array_fix

This works for 1D arrays, but is still broken for 2D arrays (due to some minor storage details). Also, array copying and memory access doesn't yet work. And printing arrays (string(a)) isn't in there yet. So it's not ready to merge yet.
Logged
Offline (Male) Goombert
Reply #14 Posted on: October 15, 2014, 09:30:07 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3110

View Profile
Hahahah, that's amazing sorlok! You're my hero!  (Y)
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Pages: 1 2 »
  Print