Fengist's Forum Posts

    Ok, this is seriously confusing. In the startup of my little project I call a function DoStuff. At the end of that function I set the return value to 1. Inside that function I call another function DoLotsofStuff without a return value under the stupid assumption that THAT function will complete, whether it has a return value or not, before it completes DoStuff and returns the 1. Instead, what I'm seeing is that DoMoreStuff fires because the DoStuff returns a 1 long before DoLotsofStuff is done.

    + System: On start of layout
    ----+ System: Functions.DoStuff = 1
    -------> DoMoreStuff
    
    * On function 'DoStuff'
    -> Functions: Call DoLotsofStuff 
    -> Functions: Set return value 1
    

    I'll mention this again. I've been writing code a long time. I have never, ever called a function in any language and have the code skip over it before it finishes even without a return value. But it appears Construct is doing just that. Am I going to have to assign some pointless return value to every function just to force it to completed before the code goes to the next event????

    And I apologize in advance. I've had an extremely aggravating morning writing code. It's taken me 3 hours to figure out why my code was not working as intended and this is the reason why.

    Please tell me this is a bug and I should fill out a bug report.

    And yea, I realize this isn't true threading but it's doing a fine job of faking it.

  • Just wondered if anyone has successfully embedded an editor like TinyMCE into a Construct project. I tried various methods of loading it up and the only way I could get it to work was via an IFrame, which doesn't do a lot of good.

  • If I'm creating a game, I'll make my own php/mysql login system. Using someone else's, Google depending on how much info they want.

  • I'm not a programmer. That's what brought me here to Construct. I do think people should be encouraged to try scripting for cpu intensive tasks like this.

    If we can get an event solution for it, that would be great.

    Yea, I'd love to see an event solution but that's apparently going to take threading which I'm learning JS apparently doesn't do all that well. That's a shame. I've played with threading in other languages and the things that can be done (scraping 50 web pages simultaneously vs 1) are pretty astounding.

    Writing code isn't that difficult for me. I know 4 or 5 languages, html and css. The problem with learning JS is that it instead of interfacing with a computer & it's hardware, it interfaces with the browser. That means it has a plethora of functions to learn that simply don't apply to other languages. The logic remains the same and the syntax isn't too difficult. It's all those blasted unique functions that cause me to spend hours digging to figure out how they work. So, learning all that gobbldey-gook JS introduces is not something I've needed nor wanted to learn. I pay Ashely and the crew to do that for me.

    It's nice know that I can write JS if it comes down to it. And I have written some functions to handle HTML changes. It wasn't because I wanted to, it's because it was the only solution.

    If I can solve things with events and not have to facedesk my way through JS, I'm happy.

  • Um, you're not using javascript?

    That's why I pay for Construct. So that I can avoid it like the plague.

  • I played around with a few ideas I had...

    This looks like what I had planned to do. I'm going to have to study this but it looks a good bit more efficient than what I'm doing.

    The CheckAllWater2 simply looks at the 8 surrounding tiles to make sure they're all fresh water as well. In a later smoothing process a lot of tiles get changed but as long as there's a 3x3 grid it should pass that process. The way I have it set now, if it doesn't find any 3x3 fresh water grid 1/3 of the distance from the center, it recreates the entire map and tries again. Since the smoothing takes a while, I'm doing this check early.

    That GameState var. Clever. I would have never thought you could call a function like that.

    Thanks.

  • What I would do in your situation (i.e. not having to change a lot, and fix the problem):

    1. Instead of calling a function that starts the while loop, keep that loop in a separate Group (default: inactive). So, instead of calling the function, just make the Group active.
    2. Instead of using While loop, use simple conditions (if conditions). That way you can have your 0.1 wait and update progress timely as everything else progresses in the game. Won't get stuck. No while loops.
    3. Make the group Inactive at the end of that loop, or when progress bar has reached end.

    This technique makes the most sense, thanks. But I'd still have to shoehorn the while into it. As I mentioned before, I'm reading an array in a spiral. In the code above t=top b=bottom l=left & r=right and represents which row or column it's looking at. As each loop finishes it either adds one to top or left or it subtracts one from from bottom or right. The reason I use a while is so that it keep running until top <= bottom and left <= right.

    I could do recursion but I spent so much time rearranging this so that c3 likes it that I'm loathe to dive into that pit again. I may just leave it without a progress update. This one only takes 1-3 seconds which isn't bad. The next one takes longer but it's much more susceptible to being broken up into chunks.

    Here, let me show you guys what I'm doing and maybe your brains will come up with a better solution than I have.

    I'm creating procedural maps. The light blue represents fresh water, dark blue salt water. I want the character to start as close to the center of the map as possible and have fresh water nearby. The while loop starts at the top left of the array that makes this map and spirals inward. The last x,y coordinates it finds with viable fresh water is saved so that from there, I can do another search for a spot for the character to start.

    I could have spiraled outward from the center and found the fresh water sooner but the logic of figuring that out hurt my head. Either way, I was looking at using a while.

    You can barely see it, but there's a green dot on the fresh water real close to the center of the map. That's the x,y coordinates the loop finds.

  • I'm British and this has always bothered me too, so much that i had taken to reversing the xy in the events so the format appeared correctly in the debugger.

    So, you moved your steering wheel to the other side and still drive on the wrong side of the road. *boggles* I think I'd be confused either way.

  • You can still use while (stop loop still will work the same way), but you'll need to track your progress manually rather than using loopindex is all.

    Of course. The problem is, while the loops is running there doesn't appear to be any way to update a progress bar, a text or anything else. One of my while loops could likely take up to 5 seconds, during which time, the game is completely frozen. Since this will be during startup, those kinds of delays are considered acceptable. Not updating a text or a progress to prove the game hasn't crashed for 5 seconds? The vast collection of impatient gamers on this planet will have a collective embolism.

    I exaggerate but you get the point.

  • Progress=/=TotalIterations

    For "loop" from Progress to TotalIterations

    -> Do x

    -> Set Progress to loopindex.

    -> Stop loop based on desired trigger

    The following tick the loop will run again, starting at wherever you left off when you stopped the loop

    And yea, I know that there should be exactly 200x200 iterations in the loops above and I could rewrite it with that in mind. The question I have is, should I really have to restructure the way that perfectly sound logic works and should I have to avoid using the while condition in the future because it freezes the app till it's done?

  • This could possibly be an interesting feature suggestion.

    A stop loop action except that instead of terminating the loop, it will complete anything that remains in the following tick.

    In Delphi there's a while and a repeat (and of course for loops) The difference between those is, in a while loop, if the condition is met anywhere in the middle, the loop breaks. In the repeat loop, it only checks at the end of the loop to see if the condition is met and then breaks.

    But, that's just me being wishful. Considering the headache I've been through with that one above, it's obvious I still haven't figured out the logic of C3 loops.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Like AlanR explained, loops in Construct are actually performed in one tick. If there is a Wait inside the loop, it doesn't pause loop execution, it creates a delayed thread. So a loop like this becomes infinite and will freeze the browser:

    > While
    stop=0
    	Wait 0
    	Set stop=1
    

    And that's pretty much what I was doing. So the whole point of me doing it this way was the result of another thread I started:

    construct.net/en/forum/construct-3/how-do-i-8/god-need-repeat-until-146195/page-2

    In Delphi, there's a repeat:until loop which is a lot like a while. It keeps doing something until a condition is met. And, as in my case, if you're doing lengthy loops, there's an application.update you can plug in anywhere and the interface gets updated. This while, it's going to take some effort to convert.

    I appreciate you guys giving me ideas and suggestions and it's apparent that I'm going to have to figure another way to do all of this without the while. All of the languages I've learned before Construct (except maybe Basic) have been function or procedure based and as little as possible goes on the main thread. And since I had this inside a function, running the timer or dt isn't going to be an easy fix.

    Here's what I'm doing:

    * On function 'CheckFresh'
     | Local number T‎ = 0
     | Local number B‎ = 0
     | Local number R‎ = 0
     | Local number L‎ = 0
     | Local number dir‎ = 0
    ----+ System: 0 is Number
    -----> System: Set T to ArrayOffset-1
    -----> System: Set B to ArrayHeight-ArrayOffset
    -----> System: Set L to ArrayOffset-1
    -----> System: Set R to ArrayWidth-ArrayOffset
    -----> System: Set dir to 0
    -----> Functions: Set return value 0
    
    ----+ System: While
    --------+ System: T ≤ B
    --------+ System: L ≤ R
    ------------+ System: dir = 3
    ----------------+ System: For "I" from B to T
    --------------------+ TerrainArray: Value at (LoopIndex("I"), L, 0) = WaterTileFresh
    ------------------------+ System: Functions.CheckAllWater2(LoopIndex("I"),L,0) = 1
    -------------------------> Functions: Set return value 1
    -------------------------> System: Set FreshWaterX to LoopIndex("I")
    -------------------------> System: Set FreshWaterY to L
    
    ----------------+ System: L is Number
    -----------------> System: Add 1 to L
    -----------------> System: Set dir to 0
    
    ------------+ System: Else
    -------------> (no actions)
    
    ------------+ System: dir = 2
    ----------------+ System: For "I" from R to L
    --------------------+ TerrainArray: Value at (B, LoopIndex("I"), 0) = WaterTileFresh
    ------------------------+ System: Functions.CheckAllWater2(B,LoopIndex("I"),0) = 1
    -------------------------> Functions: Set return value 1
    -------------------------> System: Set FreshWaterX to B
    -------------------------> System: Set FreshWaterY to LoopIndex("I")
    
    ----------------+ System: B is Number
    -----------------> System: Subtract 1 from B
    -----------------> System: Set dir to 3
    
    ------------+ System: Else
    -------------> (no actions)
    
    ------------+ System: dir = 1
    ----------------+ System: For "I" from T to B
    --------------------+ TerrainArray: Value at (LoopIndex("I"), R, 0) = WaterTileFresh
    ------------------------+ System: Functions.CheckAllWater2(LoopIndex("I"),R,0) = 1
    -------------------------> Functions: Set return value 1
    -------------------------> System: Set FreshWaterX to LoopIndex("I")
    -------------------------> System: Set FreshWaterY to R
    
    ----------------+ System: R is Number
    -----------------> System: Subtract 1 from R
    -----------------> System: Set dir to 2
    
    ------------+ System: Else
    -------------> (no actions)
    
    ------------+ System: dir = 0
    ----------------+ System: For "I" from L to R
    --------------------+ TerrainArray: Value at (T, LoopIndex("I"), 0) = WaterTileFresh
    ------------------------+ System: Functions.CheckAllWater2(T,LoopIndex("I"),0) = 1
    -------------------------> Functions: Set return value 1
    -------------------------> System: Set FreshWaterX to T
    -------------------------> System: Set FreshWaterY to LoopIndex("I")
    
    ----------------+ System: T is Number
    -----------------> System: Add 1 to T
    -----------------> System: Set dir to 1
    
    --------+ System: Else
    ---------> System: Stop loop
    

    This is still with my current procedural terrain kick.

    Basically, this loop starts at the top left corner of the array. It then reads across, down, left and up in a spiral fashion until it reaches the center of the array. It's purpose is to find a specific a number in the array (representing fresh water) then check all 8 surrounding elements to make sure they're the same. By spiraling inward, the last positive check it does will be the closest fresh water to the center. If it fails completely in finding any, it re initializes the array, and starts all over with a different one.

  • God, it's taken me 2 days to get this while to work. The thought of rewriting yet again it makes me ill. Plus, I'm going to have another much larger while loop that would be a bigger nightmare to convert into something else. Instead of completely rewriting this code into a different type of loop, is there no way to update a progress? It just seems bizarre to me that a while loop should completely freeze the app till it's done with no way to update a text or a progress bar.

  • Hell yeah, forum drama!

    But I´d agree that the output looks confusing, lucky I never worked with 3D arrays before. I like mekonbekons idea.

    I like it better than what's shown now. What I'd prefer is to show the x,y of layer 0 in row brackets and below that the x,y of layer 1 in row brackets. But I also understand that a 200x200x3 array, which is what I'm working with, is a lot of cells to put in one box.

  • So, using the trick from a for loop, I'd put a wait 0.1 in my while statement in order to update a progress bar. However, if you put a wait inside a while, the net results seems to be it locks up the entire app, which ends in an 'oh-snap' in the preview AND the editor.

    Now surely, there must be some way of updating a progress in the midst of a while without locking everything up? From what I'm seeing, if you execute a while, everything freezes till it's done.