I tried to extract the text and it works correctly while inserted as a sub-event of the cash animation it returns 0
I donât know your setup but the 2nd half (in your original event sheet) can only trigger when the animation has finished playing for an object. If the animation hasnât been completed then nothing gets created but the first half continues to choose numbers and removes items from the array until itâs empty. By the time animation finishes, Iâm assuming the array is empty.
A new random text only needs to be generated when the animation finishes. Maybe move the 1st half inside the 2nd half. Thereâs nothing to check if the array is empty. Iâm not sure what you want to happen when the array is empty. It needs a condition to check how many children exist. Then either stop creating objects or start the shuffle over again.
Yes, I have made several attempts and I believe that all the children are deleted until the array is completely emptied before creating the text.
what I would need to do is simply a way to be able to create a non-repeating random drop of ammo when the chest is opened.
I had used this method for creating powerup objects at the end of the level and I thought I could reuse this method with the creation of text but it is becoming more difficult than expected.
do you have an alternative solution?
Hereâs a method to regenerate a list of text. It uses 2 arrays. One has the text. The other array is a list of corresponding numbers. (0-3) It picks a number from the list of numbers and uses that number to pick the text from the other array. If the array is empty, it automatically refills it. It uses a button and a text object.
Note: it uses the newer syntax where if variables are setup, it doesnât need the Variable() and VariableString() part
try me: click the button to add 2 text objects
.
project: (Click the green [code] button and [download zip] open the Json file using Gdevelop
Thank you @Keith_1357 you were a great help!
one last question⌠can you tell me why I am not being taken into consideration for each instance âcassearermiâ?
the text is created for me only on the first open case, nothing is created for the subsequent ones
The object is being created at x, y but x, y are only set when the array of numbers get created.
Moving the set x and Ă˝ outside of the repeat might fix things or you could remove the x, y and set the values directly inside the create object.
Edit: I do see the line reducing y but Iâm not sure if thatâs needed if you want each to be a certain distance from the object in the for each.
Edit 2: It might be the trigger once. Trigger once works on an object level not instance. Try removing it. Itâs best to use trigger once outside of a loop or use a boolean object variable or timer instead.
Sorry for all the edits. Im on my phone. In your case, when the actions are triggered I might change the animation so itâs no longer the one that just finished. That would work as a trigger once of sorts.
Instead of using a repeat event with conditions, create an event with the condition and add the repeat as a subevent (without itâs conditions):
Thereâs a twofold benefit there:
- Itâs a much more efficient way of iterating over relevant objects.
- The trigger works as expected (in the repeat event a âtrigger onceâ doesnât function as you think it should, though logically itâs correct)
And I agree with @Keith_1357âs last comment of changing the animation once itâs completed. That would save a lot of hassle.
yes @Keith_1357 the line that reduces y I need it because I want there to be a gap between the two texts.
if this is what you meant it seems to work, now all the open cases are taken into consideration and the text is created.
the only thing that doesnât convince me is the creation of the text in the center of the case being created and then changed the text based on the child of the chosen array many times it is created laterally.
Just be aware if multiple animations finish then multiple objects get picked and then the x and Ă˝ are going to be in relationship to I believe the 1st object or instance that was created. (it could be the last but I believe itâs the first) Regardless, itâs only going to be one of the objects. It should work fine if thereâs only 1 object but not multiple.
I think the x, y actions need to be inside the for each object but not inside the repeat number of times like it was earlier. That way, it will use each objectâs position as reference.
youâre right keith⌠thank you all for your help!
I humbly ask for forgiveness, just a piece of advice⌠do you think it is the best solution to add the variable of ammunition found
Whether you show the number is completely up to you I have no opinion on that.
Iâd like to suggest that instead of using separate events for your items that you create an array of structures instead of an array of text(strings). You could then use 1 event to handle an unlimited number of items. Itâs up to you. IDK how familiar you are with arrays or structures.
This just picks a random item and shows the name and the random quantity in text objects. It uses the items minimum and maximum children for the range.
Once you create the first structure then you can just copy and paste it to add more items. The numbers are reversed because Gdevelop sorts child by name. Everything would be the same, you just need to set up the array and then add the childâs name to the variable name.
Instead of item[#] itâs iten[#].name or .minimum or .maximum
You only need the period before the child name.
I put the range in the names just for testing. You can add any number of children as needed.
Itâs all up to you. The code would be easier to read and maintain with just one event.
thanks for the example shared, now everything is a little clearer to me but I was trying to implement the creation of the double text but sometimes the same name is created twice.
Iâm most likely doing something wrong
I donât think itâs using the 2nd array like it was before. It looks like itâs using the random number instead of the number in the random number list. Itâs getting a little tougher to keep track of things but it will eventually get together.
previous
current
I think it needs to be:
set randomindex to RandomNumberList[Random(VariableChildCount(RandomNumberList)-1)]
Edit: that wasnât right. I fixed it. Itâs getting quite long. You might want to use 2 variables. Itâs up to you. Sometimes, Iâll split things into multiple steps instead of 1 super long line. You have a random number and then the number from the randomNumberList in that position.
sorry again if I come back to this post again⌠once the text has been created and the quantity found, how can I add that value to the ammunition variable?
example:
if the player opens the chest and finds arrows+5 and grenades+2
how can I add those values in âammoarrowsâ and âammogranateâ variables
What are you adding to what. Variables can be added to variables.
Set variableName + variableName
If you want to enforce a maximum quantity you could use
Say the maxAmmo was 30
Set ammo = min(maxAmmo,ammo + foundAmmo)
Or a sub event after adding new Ammo to ammo
Ammo > maxAmmo set ammo = maxAmmo
Using a variable like arraowsMax would allow you to change the value later and allow the player to carry more arrows.
I had already previously created variables for each type of weapon called:
ammoarrows
amorevolver
ammominigun
etcâŚ
I would like to add the value generated by the drop of the ammunition boxes to these variables but I donât understand how to attribute it
I thought of something like that but it doesnât work
Instead of [set] use add.
Iâm not sure if you read this or watched the intro video.
Yes, I saw the video and Iâm trying to learn, English is not my first language and I find it a little difficult to understand some passages.
I donât understand how to identify the value generated for each child in the condition and then add it to the variable in the action