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