R0J0hound's Recent Forum Activity

  • I apologize, I’m not great at reading events at the moment. I thought I had given a solution to your last question in one of the first files I posted. I think I’m causing more confusion with every new capx I post since I do things slightly different over time.

    In the last capx it just makes three shuffled value. If they are all unique (don’t equal each other) then one is picked randomly to be the right answer.

    You could just make two shuffled values and make them unique by comparing with each other and a correct answer.

    I’d recommend doing some tests to swap two values or two positions of objects. Once you can do that you have all the tools you need to shuffle anything.

    In general you could swap a and b with:

    Temp=a

    A=b

    B=temp

  • Yeah, even though I provided the ideas in that screenshot I'm confused by what it does.

    Here's a capx of that pseudo code I posted. To simplify things It uses variables, and functions to organized the steps. The sprites are all the same type and are set as the last step. Again, that was to simplify things and need less events.

    dropbox.com/scl/fi/gyhgb639n2jp2fjjckah2/shuffle_and_reorder2.capx

  • The issue you’re seeing is you cannot pick two separate instances of an object like that.

    One common solution is to use a family with just that type. But you’d need to only add instance variables to the family.

    For each sprite
    Other: instance = sprite.instance+1
    — create spriteB at (other.x+sprite.x)/2, (other.y+sprite.y)/2

    Another idea is to pick one, save the data you need to variables, use “pick all”, then pick another.

    Var otherx=0
    Var othery=0
    Var otherInst=0
    
    For each sprite
    — set otherx to sprite.x
    — set othery to sprite.y
    — set otherInst to sprite.instance
    — pick all sprite
    — sprite instance = otherInst+1
    — — create spriteB at (otherx+sprite.x)/2, (othery+sprite.y)/2
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    uce7eb3fb5aa6462b7a0b3696886.dl.dropboxusercontent.com/cd/0/get/CiDZQOc50uwrPnNAE7ZLS14aJSoEiirhsTs9R4zx3WzcqEyacQDWHAx9rwZok58uSnwsHC2woFX_CyLklqw34wXF8SvyB1RHTWqC-BVHJ84Ny7FU6QqnzBaaDOMlkxCaPp12J6a_xjeSDnGJwmhyfJLn/file

  • 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.

  • 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.

R0J0hound's avatar

R0J0hound

Member since 15 Jun, 2009

Twitter
R0J0hound has 155 followers

Connect with R0J0hound