Keyboard events inside a for loop causes error

0 favourites
  • 4 posts
From the Asset Store
7 Errors
$15 USD
7 Errors is a game where you have to find the 7 mistakes before time runs out. Can you find all 7? Have fun looking.
  • Problem Description

    ____ Any time I put a keyboard event inside a for loop it creates a error and no longer functions, I get a stack trace error.____

    Attach a Capx

    https://drive.google.com/file/d/0B3nfY4x9Y0kueHZjcEsxV2toMEU/view?usp=sharing

    Description of Capx

    This Capx demonstraights the problem I am having as the capx I was working with and discovered this problem with isn't as simple but the problem boils down to this simple demonstration.

    In the project I discovered this I am going into a for loop because I am accessing and storing key code values and gamepad indexs into a 3d array. x = device type(has different events for each device type, this is where the step 3 would be in recreation), y = buttonid/keycode, and z = player/gamepadindex. It saves those values and loads them correctly too. In a seperate event sheet it loads the saved values into the array again, then tests if the button codes are pressed and shoots out functions, again with a for loop, with keyboard events. I was making this as a custom controls template to save time on doing it. But ran into this problem while trying to simplify the project down to as few events as possible. Logically it should work, and does with the gamepad, just not the keyboard.

    I didn't feel it was necessary to upload a 60 event capx if the issue is so small, but breaking literally everything I had planed, this is not flawed logic in retrospect as the issue works perfectly fine with a gamepad, and prior to me having it simplified as such. (it was at 104 events prior to setting up for loops)

    Steps to Reproduce Bug

    • Step 1 insert a for loop, have the index start at 0, name the index something. Keep end 10 if want
    • Step 2 insert a global varible have it be any number between 0 & 10 but not 0 or 10
    • Step 3 Create a event that compares the global varible to the loopindex("name"), make sure this is inside the for loop.
    • Step 4 insert the keyboard object into the project, and insert a On Key Pressed, set it to any key such as A, make sure the event inside of the step3's event
    • Step 5 insert a text object on to the scene
    • Step 6 insert a action inside of step 4's On Key Pressed that changes step 5's text object's text

    Observed Result

    ____ What happens? ____

    A stack error occurs, and the events and actions are ignored.

    Expected Result

    ____ What do you expect to happen? ____

    I expect it to not go into a stack error and allow the action of text to change.

    Affected Browsers

    • Chrome: YES
    • FireFox: YES
    • Internet Explorer: YES

    Operating System and Service Pack

    ____ Your operating system and service pack ____

    Windows 8.1 Pro 64bit

    Construct 2 Version ID

    ____ Exact version ID of Construct 2 you're using ____

    Release 184(64bit)

    built at : 15:42:21 October 9 2014

  • Read the error: "Trigger found as subevent to a loop - this is not allowed, IDE will prevent this setup in future"

    I don't know if it works in your context, but using a non-trigger keyboard, such as "key is down" will work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Read the error: "Trigger found as subevent to a loop - this is not allowed, IDE will prevent this setup in future"

    I don't know if it works in your context, but using a non-trigger keyboard, such as "key is down" will work.

    Hmmm.... why is that? It is so odd....

    It also works with gamepad object on button index pressed....

    So it isn't like it is a genuine issue with "On" events.

    In my context I have it register both On pressed and Is down, because I have it shoot out 2 separate functions for different uses.

    Might just have to make a work around system, just thinking how now lol.

    It will have to be massive because no "Is any key down" event.

    EDIT NOTE:

    Found a work around

    created 2 global variables, if any key is pressed it changes a value from 0 to 1 for both, when any key released changes that 1 to 0 for one of them and the other gets updated every tick to 0. This would only work with the use I am trying to do more than likely.

    Also using a loop to call a function in a separate loop doesn't work out well either lol.

  • Closing as won't fix. I have no idea what you expect a trigger in a loop to do. Triggers don't run whenever you ask them to, even if you ask them over and over in a loop. Instead they fire when an event happens. They usually fire outside of normal event sheet running (especially for input events), so it's impossible it could fire during the loop. Putting them under a loop basically makes no sense at all with this. I guess the editor should prevent you doing it in the first place, and the error message suggests that, but hey, we have more interesting things to be working on...

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