One event for two possible conditions

Im trying to make it so, the same button, should make a certain object:

A - if its HP is 4 | change HP to = 2

B- if its HP is 2 | change HP to = 0 | then, delete object.


when I use the button with the HP = 4, the object is removed immediately, instead of waiting for another button click to drop HP to 0 and then remove the Object.

PS: absolute newb in here, so bear with my ignorance & thanks in advance.

How about only one event?

Imagine you have 5 animations
And only 5 hp

So set animation by number to hp

And that would be using only one event

I’ve actually tried to do it without an HP variable at all originally.

see, the player should enter a 5 digit password. and he has only three buttons as an input method (eg. A+B+C) each button could clear up to 3 characters from the password.

in this case there is two possible solutions:

1 - [ A + C ] A would clear three spots, and C would clear the last two.

this scenario works fine.


2 - [ B + C + C ] B clears one, and C clears 2 if pressed once, then another press to clear the final two.

right now, B+C, does the job immediately without waiting for the last C to be pressed.

Hello and welcome. Have you tried changing the order of events in your event sheet, where Health of Pattern 1 = 2 comes first, and after that is the event of Health of Pattern 1 = 4? Sometimes that can make a difference, because the event sheet is read top to bottom. But I’m not sure it will in this instance. You can try it anyway and let us know the results.

I totally do not get what you are talking about
I do not get what you mean by possible solutions

the first thing I did, and it changes nothing.

first of all thanks for your input anyway. It may help to know that it is more of an educational tool.

let’s assume the user sees the following pattern, which he has to clear:
[ 12345 ]

he can clear it by inputting, two acceptable combinations:

1 - A + C {from left to right}:
- where A will clear the first three digits
- then C will clear the last two.

2 - B + C + C {from left to right}:
- where B will clear the first digit only.
- then the first click of C should clear the 2nd & 3rd digits.
- another click of C to clear the 4th & 5th.

Currently:

Solution 1, works fine.
Solution 2, the first click of C after B removes all 4 remaining digits, without waiting for the second click of C.

Wait wait wait

WTF is A B C?

Cause i think i am trying to imagine it as something else than you are explaining

Would A B C be keys?

And
A removes 3 digits
B removes 1
C removes 2?

yeah, you got it right. A B C would be the buttons on your controller if you’re using one.

You are interested in text manipulation
https://wiki.gdevelop.io/gdevelop5/all-features/expressions-reference/#text-manipulation

ANd mostly SubStr()

Basically imagine we have text variable called MyText
And MyText value is idk let’s go with “I just farted”

NOW If we use StrLength(MyText) you will get number 13
Cause that expression will return length of your text including spaces
And I just farted have 13 characters
So you just learned you can count characters in your text
BUT also you can do this SubStr(MyText , 2 , StrLength(MyText)-3)
SubStr works like (text , starting pos , porition)
SO ( text you wanna target , from which position to start and 0 is starting position , how long portion of that text you wanna to get )
In other words SubStr() let’s you chop off part of text

So SubStr(MyText , 2 , StrLength(MyText)-3) changed “I just farted”
Into “just farted”
As i said 0 is starting position and it count spaces so
I j u st farted
0 1 2 3 4 … 12

So 2 is actual 3rd character here
Now so you not lose your mind
0 is starting position but 1 is one charcter
For example SubStr(MyText , 0 , 1) will end you up with I cause I in “I just farted” is at position 0 and 1 is how many characters from that point you want to display

So in other words
A key pressed SubStr(MyText , 3 , StrLength(MyText)-3)
B key pressed SubStr(MyText , 1 , StrLength(MyText)-1)
A key pressed SubStr(MyText , 2 , StrLength(MyText)-2)
Going with 1st one 3 so we go at 4th character so
I j ust farted
0 1 2 3
We want to cut from it "I space and j " so 3 characters so next character is at position 3 that is why we use 3 not 2
NOW we removed from text 3 characters so we subtract from text 3
And same logic goes for other keys

TRUST ME it looks complicated where in reality its dumb simple
Just use text object and play around with it
You will learn in no time

Can’t thank you enough, might take me a while to play with it enough to be comfortable using it. but a valuable lesson none the less.

not to waste your time any further, but how do you propose I write the event for the key that should be pressed twice.

since, everything I tried so far, seems to only prompt it to execute both events at once. and I can’t make it a one event since there’s a different conditions for each action.

These are 3 separate events
Each condition needs to have trigger once

I just write one of them so you get the idea

Condition
A key is pressed
Trigger once

Action
Change variable MyText SET TO A key pressed SubStr(MyText , 3 , StrLength(MyText)-3)

This way to delete 6 characters you need to press A twice

And you know do no BS yourself you need time
Nah you need practice
I am dyslectic in fact i have very bad dyslexia just look how i write
No punctuation sings even

And its not get any better for me with numbers
SO i do not try to even understand where should go which value

I just know SubStr(Text , starting pos , portion)

I want to start from 3rd character so i put 3 in starting pos
I need to put something in portion so i put there 100
I check what will i get using it if it does not do what i want i simply change 3 to 2 or 4 and check what that changes
In NO TIME this way i will get what i want
I DO NOT need to remember which numbers are correct
And where i need to account 0 and where not
I just need to try arround

Like imagine i am making a soup
Tell me how much salt i need to add to it? If its full pot
How many spoons?

Or maybe you would tell me to go like
Look do not bother with amount
Add 2 then mix it a little check how it taste
Repeat until you get taste you are happy with

Wouldn’t that sound more reasonable than trying to figure exact amount of spoons of salt?

Think about it regarding to SubStr()
You only need to understand principle
You don’t need to know exact value
Values you can find by trail and error

1 Like

Dude, I expected someone to point me to a page in the documentation I missed, or just give me an example of how they would solve the problem in a line or two.

Love the way you look at things, and deeply appreciate your help. I owe ya man.

1 Like

But i just gave you one?

BTW i am not 100% sure i understand what you EXACTLY want to achieve
I do not understand need for A B C keys

Like i told you before i think i am trying to understand something else from what you are explaining

Or to be precise
To my understanding you are trying to make BACKSPACE key but one that
A - removes characters from left and not right
And
B - removes multiple and not only one character

Where also
C - i am not sure do you exactly want that or remove different parts with different keys
For example if you have 12345 text i am not sure will you always want to start removing from 1 i think sometimes you want to keep 123 but remove 45

I gave you as best to my knowledge example with SubStr() so you can play with it for a moment and be able to solve your problem on your own

If you appreciate my help you do get i am trying to help
SOOOO instead of appreciate TRUST ME
Make text object
Make text variable
Set text of text object to text variable so you can always see it
And set text var to some sentence and now play around with SubStr() and different number values
That will be quickest way for you to understand it

My brother, Im saying, Im surprised you went beyond that, you did way more than I expected. Also, you gave the perfect kind of help, which guides me toward understanding how exactly such problem should be approached and resolved.

(Side Note)

You got what Im trying to do correctly, and I realize it doesn’t sound like a useful thing.

As I said it is more of a prototype for an educational tool, than a game. Im trying to learn the Metres of Classical Arabic poetry, which are as complex as they are fascinating.

There is a huge amount of [Patterns], among other more complex concepts. But Im trying to design a tool to help me get a grasp of the patterns for now; strengthen my memorization of them, if nothing else.

One more thime, thank you very much.

And i meant do not appreciate my help but try it

And reason why i wrote what i wrote is because when i came here
FOR ALMOST 3 MONTHS!!! i was seeing ppl say variable this variable that
And i was under impression VARIABLES are some kind of complex advanced thing i will need years to learn
And so i did not even TRY them for these 3 months
After 3 months i did try them to check what they are
And at that moment i had that very personal wish to have time machine
So i can go back in time 3 months and slap myself in da face as hard as possible

Trust me be afraid to not know NEVER be afraid to try something
Don’t be as stupid as i was

Side note
We help cause we help
And over time we learn how much explanation we should provide
And from my experience this much needs to be explained about SubStr() so i don’t need to answer addition questions

And on top of that check this out
I made this for other user on discord
He wanted to make wave of text

Hold space

(So believe me this knowledge is something that will come in handy sooner or later)