When to use sub-events (or is there a better way)?

0 favourites
  • 10 posts
From the Asset Store
14 amazing sound files of game events like Level Ups, Level Completes, object spawn, object taking etc.
  • Curious if there is another option to using a massive number of sub-events.

    Import 150 items into an array via AJAX, then want to order them. (this is for a chat screen that allows for sprites etc to be inserted/created in chat log)

    Currently:

    Event...Function - On "X"

    Sub-Event...Array - value.at(0)=xyz then create textbox at (1,1)

    Action...set textbox width 500, set textbox height to textbox.height (allows grow/shrink textbox height to match text)

    Sub-Sub Event...Array - value.at(1)=abc then create textbox at (1,textbox.height+10) (allows next textbox to be created just below the first textbox)

    The problem is the last sub-sub event will be 148 recessed (bad wording probably, indented?).

    Just curious if anyone has a thought on a better solution...if not no worries, this does work it just looks ugly and is hard to follow.

    Thanks

  • Can't immediately wrap my head around your requirement, but yes generally speaking you should be able to utilize loops.

    Do you have an example of your source and what the final result should look like?

  • Sounds good.

    I use subevents for EVERYTHING just to be able to classify stuff.

    I use them like you would a group.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I switched this up a little and used 50 functions (which is also not idea, but is way easier to follow the flow and takes about 1 second) since it allows the use of "else" statements for each array.x

    array.at(0) =1 then do abc (then run next function)

    else array.at(0)=2 then do xyz (then run next function)

    array.at(1) =1 then do abc (then run next function)

    else array.at(1)=2 then do xyz (then run next function)

    Still looking for alternatives, any thoughts are greatly appreciated.

  • It still isn't clear what you are aiming for.

    Are you trying to create a visual representation of an array?

    You say it is for sprites, but then your example says text boxes. You didn't describe what your array values are or how they vary, or why you need to stack so many if/else events.

    After you familiar with loopindex? If you're trying to do what I'm guessing you are, it usually takes no more than 1 event with a loop.

  • My game has a chat area that contains text (from the array...name/text/variable).[array.at(0), array.at(1), and array.at(2)]

    If the variable is 1...then it creates a text box, adds the text and moves to the next set from the array [array.at(3),4,5...etc.]

    However, if the variable is 2 it creates a textbox and a sprite (for example, request defensive troops from other members of the game) If the variable is 3, creates textbox and sprite for whatever else I want...

    I'll check out loopindex...not played with that.

  • Ok so you're using a 1d array? First off I would suggest using a 2d array. So each set of data has its own x index, and Name would go in y0, text in y1, and variable in y2.

    Actually you probably wouldn't even need the name at this point, just use the x index of each set as an identifier. I can put together an example for you if you provide me with the project file to import into the array.

    Otherwise, you can use loopindex and %3 to get every third value in a sequence.

  • TBH, not sure how to post a project file (also I'm 10k events into this, 2 years of work).

    Would you mind posting how you would parse the tokenat to a 2d array, I can figure it out if I know that trick.

    Same for the the loopindex %3, not sure where that would be placed.

    [As an update I did switch out to using sprite font and it is much much faster than textbox and cut down the number of sub-events to 6...still would like to know loops better, that seems like handy stuff and not much in the way of advanced tutorials on the web]

  • Got this down to 2 functions, variable, and a call...much happier with performance.

    1. Call function 1...add 3 to variable (allows me to set the start position for first chat post) then call function 2

    2. Call function 2 ...create next chat below first chat post, add 3 to variable, call function 2 again while the variable is below 150, else set variable to 2....ie, stop. (this is wrong I know, but it's creating a loop [manually] and I have no clue how to code that properly)

    Still if you wouldn't mind posting how the 2d array tokenat would be written and how the loopindex %3 (also the trigger events) would be written.

    Thanks for the hand holding!

  • Ok just to be clear you're trying to display a chat log, the data of which is stored in the array? I'd like to help you, but you still haven't provided either the source array/data or an example of how you want it to look (don't need your whole project). Can you take a screenshot of what your current solution outputs and looks like? And an example of the data you are importing to your array via AJAX?

    Any reason why your array is 150 specifically? Is that the maximum amount of lines you want to have displayed or history to be stored?

    Edit: Most of us use Dropbox to upload and share files. Or Google Drive.

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