farflamex's Forum Posts

  • If anybody reads this with a similar problem, I should point out that mindfaQ is spot on when he says that you shouldn't write code that freezes up C2 anyway. The solutions above (putting in timers and waits) are only needed because my processing was taking so long and causing C2 to freeze, but it's much much better (and easier to code) if you can split up your processing into smaller chunks, allowing C2 to do it's stuff. So in my case, I was processing orders for 64 teams in a single loop, but it's much better to do 1 team during each tick. That way, I can display my 'Please Wait' message and disable the 'Next Turn' message, whenever a 'processing turn' variable is set and allow the program to continue without interference from the player. When the 64 teams are complete, the variable is set back to zero and the buttons are re-enabled.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That seems to work mindfaQ, I'll try implementing that into my game.

    Littlestain, bear in mind that the 2 million loop is only to demonstrate the problem.

    I don't particularly mind locking up the game during the turn process, though I agree that it's not ideal and it's poor programming. What I was trying to do was to have a message to tell the player that it's processing and disable any buttons so that the player can't make alterations during this time. Whether it's frozen or unfrozen during that time is no big deal as far as the game is concerned. But that wasn't working the way I was doing it, though it looks like the correct use of 'wait' will fix it.

    I'm not actually sure how to stop my processing from freezing up the game, on my phone at least. It's got a lot to do and I don't want the player interfering during that time anyway.

  • It's the same in your example. It might be hard to notice, you need to double-click the box and you may see it pause, then change back, then pause again. Try it a few times. Your PC might be faster than mine so it might be unnoticeable.

    I'm trying to work out a good way of demonstrating. But basically, stuff is still being processed while it's in that loop (mouse clicks at least).

  • Yes, I'm struggling to demonstrate this properly in an example. The reason for the timer is that without it, what it does is change to the next frame then in the same tick, start the loop, meaning that you don't see the frame change (because presumably everything updates at the end of the tick?). So it changes frame then immediately pauses before showing the change, then changes back (all in the same tick, so nothing happens).

    It's hard to see the extra presses, it's not a very good example. If you really hammer at the mouse, you may see it flicker and restart another loop.

  • Yes, I'm aware that it's not actually a function (it is in my main program). I'm just using the word generically (and wrongly, sorry). What I mean is, a block of code which takes a long time to complete. The loop here is just to demonstrate. Are you saying that C2 will literally do nothing else while those 2 million events are processed? If so, I don't see why I can double-click on the sprite.

    I need to update so I'll check your example.

  • Ok, so what you're saying is, if the function is very slow (e.g 1 second) the entire game should lock up for 1 second and nothing else should be processed? That's fine and would make my life easier, but then I don't understand why it's queuing up extra presses of the mouse.

  • Here's an example of what I mean. If you click on the right-hand box, it should change colour, then you'll see the left-hand box pause while it's processing the loop on line 3 (the timer has been added otherwise you don't even see the frame-change). The problem is, if you click really quickly, it queues up more presses. Adding 'Sprite Animation frame = 0' the line 1 conditions doesn't stop this.

    https://dl.dropboxusercontent.com/u/112519761/button.capx

  • My game is turn-based and the functions can take a long time (several seconds on my phone, less than a second on my PC). When you click the 'Next Turn' button, I need to show a 'Please Wait' type message and have the button(s) become disabled. Right now, you can click the button over and over while it's processing the functions and it basically queues more turns.

    From what I can tell, the functions aren't performed in one tick. It appears to call each function immediately but then process them in a background thread or something, since you can still press the button while it's processing the functions.

  • Similar to my previous post, but that looks as though it's solved. I've solved part of the problem but I still need to know if there's a way to wait until a function has completed all of it's processing. I want my game to wait and disable the 'Next Turn' button until processing is complete (it's turn-based). Right now, I can disable the button, put in a tiny pause to show the new state of the button, then jump to my functions, then re-enable the button 'after' the functions, but what it does is, it calls the functions which begin processing and then immediately re-enables the button (even if that line is 'after' the functions or at the end of a function), meaning you can keep clicking for more turns while this one is still being processed.

  • This solves half the problem at least. Putting the timer in allows me to position the 'Please Wait' message correctly. Problem now is, when do I remove it? It needs to be removed when the functions have completed (also buttons deactivated and activated again). I'm thinking right now of setting some booleans to say the functions have started, then have them reset to false on the last line of the function (presumably that's the 'end' of the function?). Then I can test when they're all false and reset everything. I'll see how it works out.

  • Ah thanks, this looks like what I was looking for. This should work for my game, with a few alterations, thanks for your time

  • Ok, hopefully this Dropbox link will work. Hopefully it demonstrates where I'm going wrong. There are no functions, but what it does is, when you click the pink square, it 'should' change colour to blue (frame 1), then, when the loop has ended, change back to pink (frame 0). You can see that there's a pause due to the loop on line 3, but you can't visibly see the square change colour, as it's instantly changed back on line 4, while line 3 is apparently still processing.

    So my confusion here is, how can I get line 4 to execute AFTER line 3 has finished? It's not the functions that are confusing me, rather, how do I know when a group of instructions are finished, so that I can then do something else (e.g remove the 'Please wait' message as I said above).

    https://dl.dropboxusercontent.com/u/112519761/func.capx

  • Well, my game is turn-based. On my PC, the functions complete fairly quickly, but on my phone, they can be very slow. So what I wanted to do was to disable any buttons, put up a 'Please wait' message, run the processing functions, then remove the message and re-enable the buttons.

    So I guess my misunderstanding is in thinking that if the function takes a while (say 1 second) to complete, the whole game locks up while it's processing (actually, I've noticed that sprites stop moving etc in tests when I do this). But what you're saying is, even if the function takes a second to complete, the rest of the program continues to process? So how does the function process, is it processing in the background on a thread?

    To solve my problem, how do I know when the function has completed processing, so that I can remove my message and restart the next turn?

    I have capx to demonstrate but not sure how to post it.

  • I've forgotten how to post a screenshot, but in short it's like this...

    Call Function A

    Call Function B

    Call Function C

    Set Variable to 0

    All in the same event.

    A later event, then tries to respond only when the variable is set to zero (i.e 'after' the functions have completed), but it responds immediately even though the functions still appear to be processing. I basically need to set the variable only when the functions are done with their processing.

  • I have an issue where I want to change a variable only when a number of functions have completed. They're quite slow (about half a second to process them all). When they're done, I want to reset a variable, but if I put the variable reset after the functions, it seems to reset immediately, while the functions then dawdle along. I was under the impression that the final instruction wouldn't complete until the previous ones had completed, in order. Are functions threaded or something?