Change Image not working. GLITCH?

Hello, i was confused about a glitch, or maybe a self error, I have been working in blocks because I can’t quite wrap even my head around coding yet.
The issue is that it completely ignores the “change image” command and instead just freezes for a second and then it will change, let me explain . I have an “EXP” bar, and I want that smooth going up look, so I have a picture of every stage of the bar.
I made a for loop with a increase counter by one, runs the “check exp” function, and then pause for 500/ the amount of exp gained. This was in a function called “gain by exp”
It you run that same code in the “on start” it works, but if it’s triggers buy the button (I am use it a “game update”, to test if a button is pushed down) then I does not work.

Here is the link.

For anyone who can help I can explain what the rest does, thanks!

1 Like

The reason the game is freezing is because it’s pausing inside of the on game update; we talked a little bit about this in a stream last week (starting about https://youtu.be/d1yP5oa8zTU?t=829, I haven’t watched it since it’s been posted though so sorry if I’m even more awkward than I remember!). The game update is a portion of the code that has a guaranteed start and end in the game loop - it will always finish before the screen updates, so any pause in there will stop the entire game (there is more documentation for the game loop here if that helps).

Couple fixes for this:

  1. you could make the animation using the animation extension, and that should be doable in blocks still.
  2. You could try switching it from an on game update to a forever loop like we did in the video; I haven’t had a chance to look too closely at the rest of the game to see if this will work properly for you though
  3. You could move the drawing of the animation to another game update, and have it run separately - keep two variables for health (currentHealth and targetHealth) and compare the two each update, slowly moving currentHealth down to targetHealth and changing the image along the way.
  4. Another way would be javascript only - using control.runInParallel you can set code to run on it’s own, independent of the current game loop.

Hope that helps, and let us know if you have any other questions / need any clarification!

Hello Joey, (tell me if i should call you anything else)
i realized that i could make a few things better, so i did, i am still in the process of doing so, one thing that was lagging the sys. was the health bars/exp bar. i changed those to images, so that has made it better.
I am a bit confused about the

part.
I saw that part of the vid and it makes a lot more since, but what should i do, the forever loop i feel could work. so i will try that first.

I still have issues with the image though, it seems to skip parts all together, like it skips the slowly increasing part for exp. why? (also, i have not implemented the forever loop thing, so this may not be accurate).

updated link

thanks for your time,

  • Blobiy.

P.S. I did change the attacking thing so i can add more stats in the future. so in order to attack you will need to press menu

wait, omg everything works now, never mind!!! thx, the forever loop fixed everything

2 Likes

Glad to hear that! I wanted to sanity check the other solution I gave (number 3 above), so here’s an example of that one:

If you want, I’m happy to make an extension for that real quick (should have time later tonight), but I think yours looks really good as is :slight_smile:

Nice, I think i’m fine about the health bar, but thanks anyway! though i did do some work and got the health bar and made it an image, so thanks!
Although I do have so more issues, so…

  1. I have the same code for all of my “opponents”
    the issue is that the fire dude is staying in his dead image, but the other two are not.
    i am pretty sure it is a dumb mistake but…
  2. I am trying to get your character to evolve. I initially tried to just swap the character with the evolved form in the array, the issue is that
    a) it does not work
    b) it breaks the health bar, and by break I mean it just disappears
    I am still working on it, but it seems to be a wall, so I have started to work just on the “stats” for the main mon and the opponent mon.
    thanks so much btw.
    -Blobiy

sry i forgot to give u the link