R0J0hound's Recent Forum Activity

  • All the code refers to same sprite type. The new choices are a different type.

    I made all the numbers be the same type and used a group variable to differentiate between then to reduce the amount of events.

    There are many ways to setup the events. Currently it does most of the stuff with variables and only deals with sprites when displaying. Nothing is automatic. To display it picks a certain group of sprites and sets it from a certain variable.

  • Here’s the rope joint done with impulses. 100 is the max distance. The /100 at the end was to scale things down.

    dropbox.com/s/bpxf1z9zws5e1t8/Ropejoint.c3p

  • The physics behavior doesn’t provide that joint.

    A few ideas come to mind though.

    1. Is to do event based physics using verlet. I’ve made rope examples that do that. It’s as simple as if the distance is greater than a certain amount the objects are moved toward each other to correct that, then the velocities are updated. The cons are it’s independent of the physics behavior and working with ridged bodies will require more code.

    2. Joints in the physics engine are done with impulses behind the scene so in theory you could make the joint you want with that. I fiddled with the idea a bit and something like an impulse of (distance-100)/100 toward the other object seems to work but is bouncy. For better results we could copy what impulses box2d calculates for such a joint.

    Edit:

    If d is the distance between the objects and ang is the angle between them, then the impulse should be the following when dist<100. At least from what I’ve read.

    ImpulseAtoB= -(d-100+(A.vx-B.vx)*cos(ang)+(A.xy-B.vy)*sin(ang))/(1/A.mass+1/B.mass)

    I’ll test this later. The units may be off.

  • VectorX = speed*cos(sprite.angle)

    VectorY = speed*sin(sprite.angle)

  • Try Construct 3

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

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

  • 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