farflamex's Recent Forum Activity

  • Am I missing something obvious in the editor? I have 5 controls and if I hit the tab key, I want to tab through them in a different order to the order that C2 is using. For example, I have a login page which has a login textbox, then 2 password textboxes (for registration). It then has a login textbox and another password textbox on the other side of the screen, for logging in. If you're in the first login box and hit tab, it goes over to the other login box (presumably because they're the same type of control and were created together?), but I want it instead to go down to the first password box.

    Is there a simple way of doing this, other than creating completely separate boxes or redesigning my screen?

  • Thanks, lots of really useful advice there

    I've got it working now, I was making some minor errors. I'm using PDO on the server side, so the solution to protecting against injects appears to be the bindparam instruction. I was confused about the very basics of how to send my username as part of the post in C2, but I think it's simply...

    UserName=&Textbox.Text (build as a string then send in the 'data' part of the AJAX Post to URl).

    Then at my server side, I now have....

    // Already connected to database....

    $UserName = trim($_POST['UserName']);

    echo $UserName; // Obviously this is just for testing, it's picked up by C2 as the AJAX.Lastdata

    $db->beginTransaction();

    try {

    $query = $db->prepare("INSERT INTO Users

    (Name)

    VALUES (:Name)");

    $Name = $UserName;

    $query->bindParam(':Name', $Name, PDO::PARAM_STR);

    $query->execute();

    $db->commit();

    Not sure if this is all a bit over-cautious, but it does work. From what I've read, the whole 'bindparam' procedure does protect from injects etc anyway.

    One thing that was causing me problems was the strict capitalization rules. For example, 'Username' and 'UserName' are not the same, so that sent me wrong a few times

    Thanks again for your input, that really helped

  • I'm just returning to this after a break. I understand the basics of C2 and PHP etc, but I'm having a bit of trouble getting my head around a few things, because when I check PHP tutorials / articles online, they usually assume the request has come from a form or an url. So in short, let's say I'm sending a login request to my server from C2, what do I send and how do I retrieve it in PHP?

    E.G C2 would be something like AJAX - Post to Url, I use a tag, the url for the php script, 'POST' and the data. How do I post the data? Do I just send a string, e.g the user name that he typed?

    I've managed to produce a script which collects the data and echo's it back out and I also know how to add it to my database, but I want to sanitize it first. Most PHP articles suggest something like ..

    $myusername=mysqli_real_escape_string($db,$_POST['username']);

    How does the POST find 'username' from my C2 string? Do I need to add something like 'username=name' as part of the string I'm sending from C2?

  • 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.

  • 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).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

farflamex's avatar

farflamex

Member since 7 Oct, 2012

Twitter
farflamex has 15 followers

Trophy Case

  • 12-Year Club
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • x2
    Popular Game One of your games has over 1,000 players
  • Famous Game One of your games has over 10,000 players
  • RTFM Read the fabulous manual
  • Email Verified

Progress

18/44
How to earn trophies