R0J0hound's Forum Posts

  • Create by name has limited use to me because of that. But one solution is to make an “on created” for each type to set a variable. For example something like this:

    Var uid = -1
    
    On sprite created
    — set uid to sprite.uid
    
    On sprite2 created
    — set uid to sprite2.uid
    
    Start of layout 
    — set uid to -1
    — createByName(“sprite”)
    — if uid=-1
    — — set text to “no object created”
    — else
    — — set text to “new object created ”&uid

    On a side note wait 0 is a popular hack in relation to being able to create newly created objects. But I avoid if at all possible other than in quick tests.

  • It’s just an overview of how to do it.

    Previous capx show ways to represent the numbers as sprites or variables, ways to shuffle the values, and to reorder one list with another. They are building blocks to do the rest.

    I tend to break things down into general chunks like that otherwise I get lost in all the details.

    It will take a few days to get time to implement it.

  • It’s not clear from your description and screenshot what you want the code to do.

    Looks like you are looping over an array of xy positions, and comparing if the cost is greater than the any of the neighbors.

    Then it checks if the neighbor isn’t the first index (indexof gives -1 when a value isn’t found) or if the cell is one of the first four in the array.

    Other than that keep in mind setting the return value doesn’t exit the function with the event system, so all four events will run if true.

    After that I’m not sure what it does. Returns the cost with some location maybe?

    What do you want this function to do and how is it not doing it now?

  • Ah. I think that makes sense. The logic would roughly be this then. You just need a way to shuffle a list, and rearrange a list with another list.

    LettersA = shuffle(abcd)
    
    While
    — Choice1=shuffle(1234)
    — Choice2=shuffle(1234)
    — Choice3=shuffle(1234)
    — if choice1!=choice2 and choice1!=choice3 and choice2!=choice3
    — — stop loop
    
    Correct = choose(choice1,choice2,choice3)
    
    Black1 = shuffle(1234)
    
    LettersB = shuffleBy(lettersA, correct)
    LettersB = shuffleBy(lettersB, black1)
  • Here's a way to do it in a non-recursive way which loops over the array once. Basically it does it column at a time, bottom to top. It keeps track of the lowest 0 slot and if a cell is non zero it moves the value down to that spot.

    dropbox.com/s/4nip6ho8j2c8h0c/column_fall.capx

  • In the screenshot the function was called normally so it can’t take multiple frames to complete. It would run till it’s done.

    If it was run asynchronously I guess it could take multiple frames.

    The array could be considered sorted if the sub event isn’t run once in an entire loop. You could use a variable for that: set it to 0 before the loop, set it to 1 in that sub event, then check if the var is still 0 after the loop. But then all the previous recursions would need to finish all their loops of doing nothing before it was truly done.

    Another idea is to pass a depth parameter to the function When you first call the function use 0. Then each recursed call would be depth+1. Finally add another event to the function to check if depth=0, and if it is the whole function is done.

    Personally I’d write the sort in a non recursive way. Like sorting one column at a time. If for no other reason but to be more efficient. Your function will sort but it will be looping over the array a lot.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I agree that would be useful. Rendering to the canvas in the same way as the game renders to the screen would be useful. If we can't render stuff off screen it would at least be nice if we could draw a layer at a time to the canvas, instead of an instance at a time.

    Anyways, as it is now I think we could get make a mirror with the canvas. Maybe.

    Since canvas only draws correctly when the 3dcamera isn't transformed, we could replicate 3d shapes with distort meshes and transform the objects instead of the camera. With that we could transform from the view of the mirror too. Duplicate the objects on two 3d layers with a 2d layer in-between to reset the zbuffer. The bottom layer is from the mirror view and the top layer from the camera view. With some blend mode trickery we could eliminate the need for the canvas too. Which may be preferred since the canvas doesn't have a depth buffer.

    I think the biggest part would be the transformation math. My only question is if it can be fit within 25 events.

  • One way is to add a word at a time to the chunk, and measure how big that will make the chunk before adding a word. One possible way:

    var dialog = "Four score and seven years ago, our forefathers all ate pizza with pepperoni and pineapple."
    var index = 0
    var chunk = ""
    var word = ""
    
    on function getChunk
    -- set chunk to ""
    -- while
    -- index<tokencount(dialog, " ")
    -- -- set word to tokenat(dialog, index, " ")
    -- -- compare len(chunk)+len(word)+1<200
    -- -- -- set chunk to trim(chunk&" "&word)
    -- -- -- add 1 to index
    -- -- else
    -- -- -- stop loop
  • Hi,

    I had a look, but I honestly don't understand what the correct behavior should be.

    I see a row of letters, five rows of numbers, then another row of letters. What is the significance of each row? what should be shuffled? what should be unique from others? what is used to reorder another row? I'm honestly fairly confused what should be going on.

  • Good stuff!

  • It should be enough to just call a second function in the “on space” event. Then when the first function finishes the second will be run.

  • So here's an example with cubes.

    dropbox.com/s/zd3ur98uvok1523/cube_raycast.c3p

    It calculates the orientation of a 3dcamera that was set with the "look at" action.

    It then does a raycast from the mouse into the screen.

    It then positions a new cube by rounding the 3d position on a grid.

  • Here is the closest I’ve come to that. It does a raycast from the mouse to a triangle mesh. The camera has a fixed fov and orientation.

    construct.net/en/forum/construct-3/your-construct-creations-9/3d-raycasting-obj-loader-test-167475

    Basically it’s all from scratch with math as construct doesn’t provide anything that helps. Getting the ray direction from the mouse involves the inverse of the view and camera matrices. Construct doesn’t expose those, maybe you can find them with scripting, or like in that c3p you can make your own from scratch that matches. To simplify the math I went with using a fixed camera orientation.

    Then it just does a Ray vs triangle calculation with a bunch of math. Construct doesn’t provide a way to access the mesh points or list of triangles so again, we have to build that ourselves and replicate the 3D objects with distort meshes.

    With just cubes I think things can be simplified a lot. We’d still need to calculate the Ray direction from the mouse but if we used signed distance fields (sdf) of boxes we could do the actual Ray casting a bit faster.

    Anyways, just thinking aloud here.

  • Events provide the most flexibility. JavaScript would be faster but is more quirky integrating with other construct features.

    Personally I have no interest in making plugins and the maintenance they require. Also they are inherently more limited by what features are provided.

    On face value it would make sense to tie this to the physics behavior but in practice it would be better to make something completely independent.