How do you create an array?
No need for any more details ![]()
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 ![]()
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. ![]()
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 ![]()
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 ![]()
Omg, did anyone tell you that youāre great
Thank you very much. Iām so excited and will examine example right now.
Thanks! ![]()
And ask any question about the code ![]()
Hi again,
I really liked your codes. Youāre very clever indeed
. 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 ![]()
Ouch! I thought I had prevented it⦠but Iām testing it now and fails ![]()
Thanks, think of all the possibilities is a geat talent ![]()
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
. I felt ashamed to write actually.
Beceause I couldnāt get after while part
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 ![]()
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 ![]()
Also, I have to admit that my codes are usually too complex ![]()
Exactly
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! ![]()
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ā ![]()
Again, I emphatize that maybe there is some straightforward way to order a list, and Iām making it difficult ![]()
Please open a new topic, this one is 4 years old ![]()