Changing the text of variables using functions

Not favoritedFavorited Favorited 0 favourites
  • 11 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello everyone. I decided to rework my project and do some optimization. I used to use variables for each tick to display text, for example: set text = money variable .

    Such a system was quite heavy on the game, when hundreds of texts were checked each tick, which might not even be used.

    I decided to make an easy way. When starting a layer, set the text, and then, by pressing a button, call a function that will update the entire text.

    However, I encountered very unpleasant errors. When pressing a button, the text may not change, and when pressing it again, the text will get the previous value, etc. Accordingly, the animation frames or coordinates also do not have time to update. Despite the fact that first I change the variable, and then use the function. I tried using wait 0, wait 0.01, but this does not solve anything special.

    Is there any way to make such an optimized mechanic? or not?

  • Can you show the events above the "On tap" one? Is it nested under any other conditions?

    Also, please post screenshots of those functions - Change_Details, Details_Update

  • Can you show the events above the "On tap" one? Is it nested under any other conditions?

    Also, please post screenshots of those functions - Change_Details, Details_Update

    One tap

  • Okay, so what exactly isn't working? What do you see, and what should be displayed instead?

  • Okay, so what exactly isn't working? What do you see, and what should be displayed instead?

    I press the button changing the variable, for example. Which sets the text.

    For example, the variable = 0. I press the button, it should be 1, then I press it should be 2. I add one at a time.

    The variable itself is added if you look in the debugger, it is 1, 2, 3, etc.

    And the text that is displayed set text in the function is delayed by one click. That is, if the variable is 2, then the text will show 1. And this applies to coordinates, animation frames and other moments. From here it introduces me into some kind of dissonance, as if the text changes first, and then the variable. But under the conditions, first I change the variable, and then the text, and I change the text in the function.

    I was just able to solve this problem by setting wait 0 sec. However, this is wrong, and I do not understand how to do it without wait

  • I press the button changing the variable, for example. Which sets the text.

    Which variable and which text?

    Are you talking about Index3 and "Engine_Type_Text"? The text should display (Index3+1)&"/5"

    So when Index3=2, then the text would display "3/5". Is this not the case?

    It would be a lot easier if you could share the project file.

  • > I press the button changing the variable, for example. Which sets the text.

    Which variable and which text?

    Are you talking about Index3 and "Engine_Type_Text"? The text should display (Index3+1)&"/5"

    So when Index3=2, then the text would display "3/5". Is this not the case?

    It would be a lot easier if you could share the project file.

    No, that's not it at all. We're talking about a real delay, not as stated in the text.

    I can say that no wait 0 will help now. The project works on its own. Adding more and more different new systems makes it work worse. And I don't understand at all how to track it, even through the debugger.

    Here are two screenshots for you as an example. At the first stage, all the texts indicate the beginning of the layer and successful use of ajax. In the second place, identical actions, but in functions. THE TEXT IS NOT DISPLAYED IN THE FUNCTION. Absolutely. I don't understand at all where the delay is and what the problem could be. We're not talking about Engine_Type_Text, we're talking about all the texts that are on the screen.

    Or another point. With variable 0, the sprite position is on some coordinates, with variable 1, the sprite position is on other coordinates.

    Here's an example

    variable 0 = x.sprite -> 25

    variable 1 = x.sprite -> 45

    When the layer starts, we get x.sprite = 25. I press the button, the variable has changed to 1, the coordinates are still 25. I press the button, the variable is already 2, the coordinates are 45.

    Although variable 2 does not set any coordinates. :/

    I press back, to variable 0 = the coordinates are again 45. Although they should be 25. I press the button again so that the variable is -1, and the coordinates are again 25.

    I don't understand at all what's going on, why are the functions lagging and how can I display the text if not every tick ??? Where every tick works perfectly.

  • > I press the button changing the variable, for example. Which sets the text.

    Which variable and which text?

    Are you talking about Index3 and "Engine_Type_Text"? The text should display (Index3+1)&"/5"

    So when Index3=2, then the text would display "3/5". Is this not the case?

    It would be a lot easier if you could share the project file.

    drive.google.com/file/d/1b-_h-VZD3Rymb5cKaTsZuQEoG-3M9esB/view

    And so I was able to repeat the error with the coordinates moving. Press the up button and see that the square has changed color and moved. Press up and see that the red stripe has moved down.

    Now look at the code.

    The square that changed color to cyan can NOT have a red stripe on top. Only by duplicating the button press did it take the position.

    I have the same error with text, display, etc. Check carefully. Study the image points. I don't understand the logic.

  • https://drive.google.com/file/d/14LSazQCyuVtHWaIg6bI0pArboNY4vNIh/view?usp=sharing

    You were changing the position of the red square before changing the frame, so it positioned to the image point of the first frame. The second time you press the button the frame has already changed so the red square goes to the bottom.

    I dont think this is going to help you with your initial problem tho. That one is too much for me. But maybe will help to check if you are referencing something in your events that didnt happen yet.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Superxonic is right — The first time you press the Up button and the function is called, the frame is still 0. Events 3 and 4 will only update the animation frame on the next tick. Move Events 3 and 4 inside the reload_position function to fix this particular issue.

    I imagine something similar is happening with your texts — likely due to the wrong order of events. Though it's hard to tell from your screenshots. For example, if you’re receiving data via AJAX and want to display it immediately, the correct sequence should be: Load the data into variables -> Then update the texts

    It looks like you might be updating the texts before setting the variables. But again, not possible to tell with the provided screenshots.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)