Mouse Click

Started by Vincent, Wed 24/01/2018 11:12:45

Previous topic - Next topic

Vincent

I have a "button bar" which his width increase anytime you click another button. I have a working script which in some computers works fine but for other computers it doesn't work very well. I figure it out that (maybe) it's regarding the game speed and how certain computers handle the game speed and process the mouse clicks. I just wish to understand how can I fix this script so to make this working very well for each computer. I will try to explain you what I would like to do.
1) Click the button increase the "button bar" width +2 unity
2) Set timer to decrease -1 unity the "button bar" width
The main goal is to click repeatedly fast the button as you can to increase the "button bar" width. As I explained previously the script is working fine but for some computers. For other computers you simply cannot increase the "button bar" width because (I believe) the timer expired very much fast. So I really don't have a clue on how can I solve this problem. I would need any of your advice if you don't mind. :(
Here is the script:

Code: ags

int ButtonClicked, Buttonlength;

function repeatedly_execute() 
{
  if (IsTimerExpired(5)) // decrease width "button bar" 
  {
    if (ButtonClicked != 0) {ButtonClicked --;}
    if (ButtonClicked <= 0) {ButtonClicked = 0;}
    SetTimer(5, 3);
  }
  Buttonlength = FloatToInt ((IntToFloat (ButtonClicked)/159.) * IntToFloat(Game.SpriteWidth[BtnBar.Graphic]));
  BtnBar.Width = Buttonlength;
}

function ButtonPush_OnClick(GUIControl *control, MouseButton button) // increase width
{
  if (button == eMouseLeft)
  {
    if (BtnBar.Width < 585) 
    {
      ButtonClicked += 2;
      SetTimer(5, 3);
    }
    else // button bar has reached the full width
    {

    }
  }
}


Please any kind of help is truly appreciated.

Khris

I implemented the code, and I have to really, really mash the button to get the bar to grow. I assume other testers had the same issue.
Then I increased the delay from 3 to 6, and it's still challenging but possible.

The game seems to decrease the width by 1 each 3/40 seconds, or by 13.333 each second. Which means one has to click seven or more times per second to make the bar grow. Seems a bit much?

I'm wondering though, does your game run at 40 FPS? And is it set to 40 FPS? Just call Debug(4,1); in game_start to activate the frame counter.

morganw

As far as I know, the built-in timers are linked to game ticks and the time between ticks can increase depending on computer load and vsync settings. It would probably be more predictable to implement your own delta time (so check the time on each tick and increment a variable based on the time that has passed) as it will account for engine slowdown. You could also use a random element based on the bar width, so that it is easier when the bar is emptier and give some element of chance when you need to be clicking faster.

Vincent

@Khris:
At the moment the parts regarding to increase +2 unity and decrease -1 unity the button width it's not really what I am doing at the moment. I said in that way just to let people understand what I am trying to achieve. So in my final script I am increase the width by +6 unity and decrease it by -3 unity which is working/looking good (for me and for some other testers) and the timer delay it's still set to be 3. With these value it's not really easy to increase the button width, but, of course still possible to see the button width that grown til his max value while pushing the button repeatedly. The main problem is that for some testers no matter how fast they push the button, they could only see a really small portion of the button width that increase. They are not be able to make it grown more than this small portion. :( So I don't know can I fix this problem... How can I do something like this which is working well for each computer? However I didn't set the game speed manually throught the script. So I think it is set to be with default value 40 fps I believe. I have called the debug command into the game_start and it travel in this way: 1, 5, 10, 12, 11, 12, 11, 12, 10, 6, 8, 9, 12, 10, 11, 13... and my graphic driver is set to be software renderer. (which I don't know if that make a difference)



@morganw
Probably you are more than right. "the built-in timers are linked to game ticks and the time between ticks can increase depending on computer load" this would be the reason why on some computer it work differently. Your idea to make a custom delta time seems cute but how do you achieve something like this? Also, regarding your other idea I didn't understand at all.


I am truly glad that you guys are helping me with this problem, I just wish to make it work good for each computers...

Khris

Quote from: Vincent on Wed 24/01/2018 23:25:431, 5, 10, 12, 11, 12, 11, 12, 10, 6, 8, 9, 12, 10, 11, 13...
Wow, you do realize that it's supposed to more or less say 40, right? The value is the current frames per second as measured by the engine, and it should match the game speed.

A low FPS value like that means that your game only runs at a quarter to a third of the speed it's supposed to, which is why you can easily make the button grow because you can probably get a click in about every other frame.
Whether you're going to use +6/-3 in the actual game doesn't matter, the ratio is what matters, and it's still 2.0, meaning you still have to click seven times per second to overcome the bar's shrinking on a computer that runs your game at 40 FPS.

How come your game runs that slow? What other stuff are you doing in your repeatedly_executes?
If your computer is that slow, you might want to set the Game Speed to 10 or so, although that will result in choppy everything.

morganw

Actually, making your own timer doesn't seem possible as you can only retrieve the time as an integer. So for a different approach, I tried to fake it by smoothly decreasing the bar width on each game tick and set the width on the click event (but including a slight random element).
Code: ags
int STEP = 1;
int TARGET = 0;
int START = 200;

function repeatedly_execute_always() 
{
    if (BtnBar.Width > TARGET)
        BtnBar.Width -= STEP;
}

function room_AfterFadeIn()
{
    BtnBar.Width = TARGET + START;
}

function BtnBar_OnClick(GUIControl *control, MouseButton button)
{
    if (button == eMouseLeft)
    {
        int step = Random(3) + 10;

        if (BtnBar.Width <= 585 - step)
            BtnBar.Width += step;
        else
            Display("Win");
    }
}


You might have to tweak the numbers, but this way it isn't relying on the mouse events to directly work against the resizing of the bar.

Crimson Wizard

#6
Quote from: morganw on Thu 25/01/2018 19:03:44
Actually, making your own timer doesn't seem possible as you can only retrieve the time as an integer.

Did you mean "as seconds"?

BTW I made my Timer module a while ago, but it's made in kinda cheaty way because it assumes the game is running exactly on the GameSpeed user sets. From that perspective it is no better than built-in timer.

morganw

Quote from: Crimson Wizard on Thu 25/01/2018 19:08:51
Quote from: morganw on Thu 25/01/2018 19:03:44
Actually, making your own timer doesn't seem possible as you can only retrieve the time as an integer.
Did you mean "as seconds"?
Yes, DateTime.RawTime returns an integer, so it wasn't as 'raw' as I was expecting.

Vincent

@Khris:
Yes, I realize that the game speed it's supposed to travel to 40 fps so far and indeed I was surprised that the game speed travel so low for me. So this is the reason why, maybe some testers can run the game exactly on 40 fps or so (differently to me I believe) so they cannot make the bar grown in any cases. :( The weird is that for some testers the game run like my computer so the bar width work just okay. Not sure why the game is running so slow but I can give you this info: Game resolution is 1280x1024 (my monitor resolution is 1024x600) I am using OGG Theora video plugin done by scotch. I am not doing anything special in my repeatedly executes only a bunch of "IsTimeExpired" to check some timers status only, nothing more. In repeatedly execute always I have something like this:
Code: ags

if (video != null)
{
  video.DrawEx(DsScene, 158., 95., 0., 0., 0., RtScreen);
  video.NextFrame();
}

I have try to set the game speed to be 10fps at start of the game and I can see the game a little choppy but not that much?! (which I think it's weird or not?!) The thing is that for me and for some testers the script that I showed you before work as it should be, it work everything fine. But I need to understand how can I fix this problem for other computers too. I also can say that the button width doesn't grown more than the little portion on a powerful computer. If it is something about the ratio how can I fix it? :( Or better how the game can recognize the proper speed to use according with the computer? :(


@morganw:
I would like to try out to use your script and I will let you know how does it run for me (and for the other testers too). It might could be a solution (I hope), thanks in advance for the time you spent to do this for me. I will let you know as soon.


@Crimson Wizard:
Do you have any idea on how can this problem can be solved so far? Any kind of ideas is okay.

Khris

Look, it's like this: if the game runs at 40FPS, like it's supposed to, the bar is almost impossible to fill because it shrinks too fast. If however the computer is slow, the game runs much slower, which means you can get more clicks in and thus make the bar grow. I don't know how else to explain this. Did you watch the first Spider-Man movie where Tobey Maguire easily dodges Flash's attacks in the school's hallway? That's basically what a user can do to your game if it only runs at 25% of its speed setting.

The solution here is not to "fix" the ratio so the bar works on fast computers, the fix is to find out what's wrong with your game and fix it, so it runs at 40FPS on all systems. And once it does, all you need to do is increase the delay from 3 to 5 or 6, and everybody will experience the bar like you do.

Vincent

Khris I understand, thank you very much for the explanation. The main fix is to find out what's wrong with the game and fix it so to make it run at 40 fps on all systems. The only pain in that place is that I can't figure it out why it's running so slow.

Crimson Wizard

By the way, even though DateTime.RawTime's precision is only 1 second, it may still be possible to adjust game calculations in accordance to real FPS.

You need to count game ticks in repeatedly_execute_always (simply incrementing an integer variable), and when RawTime changes, you know that your real FPS is roughly number of ticks you stored in variable, or rather number of ticks it increased since the last second.

Knowing that, you could adjust all your time and speed-related values using relation between GetGameSpeed() and "real FPS".

PS. Hmm, need to experiment with that, probably this will also work for custom timers.

Vincent

#12
Crimson Wizard, I understand what are you talking about. Maybe even your idea could be a good one. I will just need to make it work all of this right without any issues. Also, I tried to run the game without video and fps are show to 40 now.

Ps: morganw script works perfectly fine for me. Anyway, now I have to test this with the other testers as well to see how does it work at all.

Khris

I can only repeat that pursuing this is useless in the long run. What's puzzling to me is that the people who had issues with the bar didn't notice that the game runs 4 times the speed it's supposed to run, given that it's developed on a system that runs it at 10FPS. One would assume that the game's entire timing is off, and that people who run it at 300% to 400% the intended speed would notice that fact...?

Vincent

Khris you are totally right about it. However yes, other people who have tried the game on a more powerful computer have reported that the game runs at a higher speed than I programmed it both for some of the timing and for playing the videos themselves. When they said so I opened this message with the hope of understanding what was happening. Yesterday I realized that the slowdown for me is given by the videos. In fact, if I play the game without video, then the fps are correct as they should be. Right now I'm trying to run a video with a lower resolution for example (640x480) instead of (1280x720) and see if my computer makes any difference.

Vincent

@Crimson Wizard:

Do you remember about this thread?
http://www.adventuregamestudio.co.uk/forums/index.php?topic=55649.0

Well, I understand that no matter the video resolution of whatever. If the game resolution is 800x600 or higher then the game run with OpenGl which is work very slowly for me. If the game resolution is less than 800x600 then the game run with Software renderer and fps are 40. This is the problem and I figure it out now.

SMF spam blocked by CleanTalk