Fengist's Forum Posts

  • Ok, now sure how much visibility this will get in this forum but here goes.

    https://twistedvoid.com/C3/NewsTest/index.html

    If the link to the app is TLDR then here's the basics:

    This is formatted HTML news that can be placed in any C3 app that was automagically produced from posts on a WordPress website.

    So, how much interest would there be in something like this?

    Tagged:

    Doesn't seem to happen here, Fengist...

    Check this file.

    You don't need any "wait" for the functions to be executed in the correct order.

    Without seeing your file is hard to tell the problem, but something must be messing up your logic...

    Cheers!

    Change your code. Add just a Wait 0 here:

    * On function 'doLotsOfStuff'
    -> System: Wait 0 seconds
    -> Text: Append " Starting to execute doLotsOfStuff" & newline
    ----+ System: Repeat 10 times
    -----> Text: Append " Doing " & LoopIndex +1 & " stuff" & newline
    
    ----+ (no conditions)
    -----> Text: Append " Finished executing doLotsOfStuff" & newline
    

    which completely changes the order of your output. THAT is what I was experiencing and it was totally unexpected.

    *grabs popcorn*

    I don't understand why you'd use this weird setup with return value. Why not just do

    FunctionA

    FunctionB

    FunctionC

    ...

    And maybe use signals/wait for signals if needed?

    The reason I inserted waits into my functions was because I was doing a bunch of functions. The purpose of the waits were to temporarily stop loops and whiles (which I've also learned can't be done without making an infinite loop) to update a progress bar or some such. And that is something that was suggested to me in a previous thread as a way of pausing a loop to show progress. So I stupidly assumed that if Wait 0.1 worked then Wait 0 should work the same way only faster.

    That return value was inserted as a result of debugging because was trying to force it to wait for the previous functions to complete before executing the code below it, which it was having none of because a single Wait 0, buried 4 functions deep, was causing it to return that 1 regardless of whether everything else had been completed or not.

    Yea, signals would have worked, I was trying to be expedient.

    It's common that people run in to a problem and then they immediately blame Construct. I would discourage you from doing this - not only is it somewhat tiring, it's also not the best way to investigate and diagnose a problem and will probably just send you on a wild goose chase which will only increase your frustration. A better approach is to basically take a debugging approach. For example you could add console logs frequently through the events, with messages like "Starting funcA", "Finishing funcA", "Step1", "Step2" etc. Then you can easily see in the console the specific order that everything ran in. This then helps figure out where things are diverging from what you expect, and helps you hone in on why. Chances are it's working as designed (but remember events are a pretty different paradigm to traditional programming languages, so in some cases the intended design may not be identical to other typical languages). Even if you become convinced it's a bug, you then have a project ideally set up to either share on the forum to ask about why it's working that way, or post to the bug tracker as a project demonstrating what you believe to be a bug.

    Where the hell did this bitch slap come from?

    If you read my posts, nowhere did I blame Construct. I did ask if this was a bug which is not an indication of blame. When I was told the reason, I blamed JS.

    The way I discovered this WAS through a debugging approach whereby I inserted a breakpoint at the start of the event sheet and watched as it sent back a return value from a function without completing the function. In my coding experience I have NEVER seen a language that has anything I can insert in the middle of a function that tells it to both complete AND break out of the function at the same time, which is what Wait 0 is doing. While I do see the potential benefit of doing that in rare circumstances, it's not something I've encountered ever before and therefore is not something I would habitually look for as a coding error which is why it took me hours to finally track down. Furthermore, IMHO, the fact that Wait 0 and Wait 0.01 do two VASTLY different things (if what I'm seeing is correct) is also absurd.

    And if you keep reading my posts, you'll also see that I did create a test project, which I shared and which demonstrated why the Wait 0 in a function is nothing short of illogical. By simply turning it on or off, I can completely change the order in which functions are completed.

    On the other hand, if you just keep making random changes to an event sheet, and always want to blame something other than the logic of your events, then yeah, you'll probably have a hard time making progress!

    What? Where the hell did you get that I was making random changes? My logic? Is that some petty insult? You're accusing me of being stupid and illogical in my approach to solving this? Well, I know how to respond to that. I can take me and my stupid illogical wallet back across the pond.

    As a rule of thumb, I steer clear of "Wait 0". Rarely do I really want to postpone actions back to the end of a tick.

    Yea, I see that now. Here's the problem. The list of things I'm learning to avoid (loops, while, etc.) is growing at an exponential rate. By the time my subscription comes around for renewal, I'll be coding on paper with a pencil.

    Are you a JavaScript programmer usually?

    Nope, several other languages but not JS.

    Ok, so, setting the wait to 0.1 does solve the problem but. Having wait 0 and wait 0.1 do two different things???

    Where did this JS language come from any way?

    Oh, I figured it out and this is even crazier than I thought.

    + System: On start of layout
    ----+ System: Functions.Function1 = 1
    -----> Text: Append newline&"Function1 complete"
    
    * On function 'Function1'
    -> Functions: Call Function2
    -> Functions: Set return value 1
    
    * On function 'Function2'
    -> System: Wait 0 seconds
    ----+ System: For "" from 1 to 5000000
    -----> (no actions)
    
    ----+ System: 0 is Number
    -----> Text: Append newline&"Function2 complete"
    

    Do you see the difference? At the start of function2, I added a wait 0. With the wait 0 enabled, function 1 completes first. With it disabled, function 2 completes first.

    Wow, just.... wow. So, the method that was described to me earlier on one way to update say a progress bar in the middle of a loop by inserting a wait, completely breaks the chain functions should follow.

    Ok, I have no clue what's going on. I just did a test.

    + System: On start of layout
    ----+ System: Functions.Function1 = 1
    -----> Text: Append newline&"Function 1 returned"
    
    * On function 'Function1'
    -> Functions: Call Function2
    -> Functions: Set return value 1
    
    * On function 'Function2'
    ----+ System: For "" from 1 to 50000000
    -----> (no actions)
    
    ----+ System: 0 is Number
    -----> Text: Append newline&"Function 2 finished"
    

    And this works as intended. Function 2 completes before function 1. So I have no idea now why my code, which is essentially the same but a lot more complex, is not doing this.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads

    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.