Hello
As you probably know, i am learning the creation of extensions with only functions for the moment.
The functions already made, concern expressions on numbers and strings.
Below, you can see the list of these functions: (the CenterSpriteOnScene function is not mine but i used it to learn how to write functions)
With numbers:
“Choose_Number”: choose a number among a list of 6 numbers Not all time perfect
With strings:
“Choose_String”: choose a string among a list of 6 strings Ok
“Concat_2_Strings”: append a string to another Ok
“Inverse_String”: inverse the characters of a string Ok
“Word_In_String”: verify if a word is inside a string Ok after correction
“Nb_Vowels_In_Word”: returns the number of vowels in a word Ok
“Nb_Consonants_In_Word”: returns the number of consonants in a word Ok
During writing these functions and precisely “Word_In_String”, i noticed some strangely things. Ok after correction
I’ll bring to you later more details.
Keep on creating. Extensions in Gdevelop is a super power!
Functions are very useful especially for repeated tasks. They save you from having to repeat large blocks of the same group of events. They also make the main event sheet more manageable and less overwhelming.
I’ve been playing around with a process for finding if tiles are connected by neighboring tiles. When you check the 4 sides, it much easier to call a function that takes parameters with an offset instead of using the same block with 4 different offsets.
Usually, anytime you notice blocks of nearly identical events, you can usually save time (in the long run) by creating a function.
The find a word technique is a challenge. I’ve helped people before and the best way for that was to make sure there was a character like a space before and after each word.
So, if the words were “the quick brown fox” then the entire string would have added spaces not just between words but also at the start and end. Meaning " the quick brown fox ".
Then when you searched for a word, you would also search for the spaces. Meaning " own " instead of “own”. That way it would only match if there was " own " and not “brown”. It would be more challenging without spaces like say there was sometimes a space and sometimes a comma without a space. Then you would also need to check for the comma or non-alphabetical characters.
I guess you could split the text into an array using the array tools and then search the array for an exact match. But, searching a string is quicker than splitting a string and then searching the array.
If you could split the sentence into a structure then that would be easier to check for a child. But, again. Just searching a single string would be quicker than splitting and searching.
It all depends on the overall need like the size of the text being searched and if you control the formatting or the user types something.
Modifying data is easier when using Javascript. My Javascript skills are a bit weak. I know most of the language but not some of the techniques. I can write short bits of Javascript with help. I would only add Javascript event groups when absolutely necessary. While it works. It makes it tougher for me to read. It’s not as smooth looking.
Thanks for your reflexion and your encouragement.
Keyth, you are right: i also noticed that Espace in the beginning of the string where to find a word, produced a right result.
And without this espace in the start of the string, the result is always wrong, except if the string and the word to find are all of 1 character.
Solution and it is very simple in fact: i’ll add systematically, by event, an espace at the beginning of the string where to find the word and it’ll be good.
Thanks again to you all.
I confirm: it works with the method to prefix with an espace, the string where to do the research.
I am going to fix soon the “Choose randomly a number” function because i don’t agree with the obligation to use this function with 6 numbers.
Then next, i’ll add anothers.