Array Creation

How do you create an array?
No need for any more details :smiley:
P.S. I am trying to use it for random terrain generation.

Array are not “officialy” in GD but you can find an extenson here made by victor : gd-extensions.victorlevasseur.co … nt&lang=en

But care currently the extension is for GD 3.1.6.1

Thanks!
Also can you check my other post about a transparency problem?
THX!

I reply on it :slight_smile:

Like @loustak said arrays are not officially supported by the current version of GD, and to be honest I don’t see the advantage in work in an older version of GD, because you’ll had to deal with a lot of bugs that have come fixed since then.

There are another ways to resolve the “array” thing in GD. There are ways to load and simulate arrays and work with a specific object of a collection.

A few days ago I released the source project for a small game of mine, there are some “array work-arounds” that maybe you can find useful.

You can download the source project from this thread: [url]Group-It source project released]

Hope it helps.

You can also use structure syntax, for example :

myVariable["1"]

(quotes are importants).

GD support structure variables, read more about it here: wiki.compilgames.net/doku.php/en … evariables
And you can simulate array using structures as victor said. :slight_smile:

I’m not understanding how it works

Let me explain it:

Ok, I have this structure:

myVar { 1; 2; 3; }

(That’s just pseudo-code but you get the idea)

As I understand I can access this variables by using this syntax:

GlobalVariable(myVar.2)

(Assuming “myVar” it is a global structure and I want to access to the “2” child value)

But in your syntax example you’re showing something like:

myVar("2")

This is analog to your example and as you can see you are directly using the parent variable name and then putting the child variable name between quotes and square brackets.
[b]* Ok, I mean, that really works? The expression editor seems not validate anything remotely like.

  • And then, how to specify if it is a scene variable, global variable, object variabe or object instance variable in this way?
  • And even more important: how it works for deeper nested structures?
    [/b]

I mean :

Variable(myVar["2"])

Cool!

Thanks.

Hi all.

So let’s say I have soccer teams. How can I sort them with points and show in a table or text objects ? Just like league table.

Order a list is a bit complex, I made an example :slight_smile:
OrderList.gdg (32.5 KB)
Press “Space” to switch between an unsorted and a computed-in-place sorted list.

The “magic” is the doble iteration, (variables “i” and “k”), “i” follow a specific item, and “k” check if the others items in the list are greaters or not, finally, sort the list in function of how much items are greaters:
The greatest has 0 items greater, so the greater is in the place List[“0”]
The second has 1 item greater, so the greater is in the place List[“1”] …

It will work better if the initial list (unsorted by points), is sorted by (e.g.) name :wink:

Omg, did anyone tell you that you’re great :slight_smile: Thank you very much. I’m so excited and will examine example right now.

Thanks! :smiley:
And ask any question about the code :slight_smile:

Hi again,

I really liked your codes. You’re very clever indeed :slight_smile: . I think I just wonder what if there were teams that have same value of greaters.

TO[VariableString(greaters)].Name

If so, the latest team that has same value of greaters will be overwritten to the same TO[ID] I guess ? I don’t know if I’m right. If so how can I prevent that ?

Thank you very much :slight_smile:

Ouch! I thought I had prevented it… but I’m testing it now and fails :unamused:

Thanks, think of all the possibilities is a geat talent :wink:
This (apparently) woks:
OrderList.gdg (36 KB)
Just added a void array, then I add old greaters values used in it… Finally, If the value is unique just put it in the new list, but if it was used before (it’s in the array with old greaters values), increase it until it isn’t in the array…
Oh, and made a slight change in the condition “Curent item value >= Other items values”, from “>=” to “>”, otherway I think it’ll not work…

Let me know if something isn’t working as expected.

Once again I’m very impressed, thank you really. It works perfect.

I really spent my day to examine your code :slight_smile: . I felt ashamed to write actually.

Beceause I couldn’t get after while part :blush: Greaters_used was a variable but with while function it become structure I guess. and greaters become it’s child. So if it become it’s child in while loop, shouldn’t it always exists ? I mean isn’t it like

greaters_used.greaters = greaters

if greaters_used.greaters exists then;

add to greaters

So how doesn’t it becomes an infinite loop ?

I’m sorry maybe this is a silly question but I’m not smart enough I guess :blush:

Don’t worry… about the code: Probably you will not have to write complex codes like this, I mean, you haven’t to sort a list everyday in GD, and I can see now it is not easy :stuck_out_tongue:
Also, I have to admit that my codes are usually too complex :blush:

Exactly :slight_smile: When you start sorting, you need the array “greaters_used” empty, so you need to delete every child (you can do it if you want), but GD allows you to convert the type of a variable, so I convert it for an instant in a number… and delete every child in one line! :smiley:

The wile loop checks if the child with the name of “greaters” exists (i.e. “0”,“1”,“2”…), if it exists (there is another item in that place), add 1 to “greaters”, then the while checks again if the child exist… but this child is greater, some day the “greater” will become a number that isn’t in the “greaters_used”.
For example, in the file I uploaded here, First_Team has 18 points, and Second_Team = Third_Team = 15 points…
The Second_Team has 1 team “greaters” (remember I change the condition “>=” to “>”), it has no problem with the “greaters_used”, so it will be in the index 1 (second position) and the number “1” is added to “greaters_used”.
The Third_Team has 1 team “greaters” too, but the while loop check that “1” exists in “greaters_used”, so add 1 to “greaters”, now the while loop check if “2” exists, it doesn’t, so Third_Team is added at index “2”, and “2” is added to “greaters_used” :slight_smile:

Again, I emphatize that maybe there is some straightforward way to order a list, and I’m making it difficult :smiling_imp:

Please open a new topic, this one is 4 years old :smiley: