Yann's Recent Forum Activity

  • Sprite: Set angle to self.Angle + dt*360/(24*60*60)

    should rotate the sprite a 360� per 24hours

  • Yeah random(a,b) gives you a random number in the [a;b[ range. For global variables, as soon as you nest them under an event or a group they become local variables and their scope is only in this event (and related sub-events) or group. Now, if you set your local variable as static, they will behave like global variables (meaning their value won't be reset at each tick) As far as boolean goes, inded you can't have boolean global variables. But you know, booleans are just 1 or 0 under the hood. If you really want to use TRUE and FALSE instead of number, you can still define them as constant of value 1 and 0.

  • By the way InvaderX... You should use loops when you repeat things

    +On start of layout
        +repeat 14 times
            -> create Tree on layer 1 at (random(1024),random(1024))
        +repeat 10 times
            -> create Wall on layer 1 at (random(1024),random(1024))
  • Hm, the thing is, you're not really using Arrays here. You just put some instance variable on the array and use these.

    Every object can have instance variables. It's not really what arrays are for (:

    Also, I think that your expression could be simplified this way:

    newPrice = round(formerPrice * random(0.85,1.20))

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The dictionnary object is quite simple, I even think it's simpler than the array object.

    It just associate a key and a value.

    if you do

    Add value 3 at key "myNumber"

    you can retrieve it by doing

    Dictionnary.Get("myNumber")

    The same way you do Array.At(anyNumber)

    But since the key is a string, you can do all kind of tricks by formating the key to fit your needs.

    Like:

    Add value "My awesome dialog here!" at key "arc_day_timeOfDay_place_theInteractive_characters_Objects_Items_Default_AutoDialog"

    if you do

    dictionnary.Get("arc_day_timeOfDay_place_theInteractive_characters_Objects_Items_Default_AutoDialog")

    it will return "My awesome dialog here!"

    So in a way you'll emulate a multi-dimensionnal structure.

    The only downside is that you don't know the size of each of the dimensions... (unless you keep track of them yourself (:... in an array for instance)

  • I don't remember what is my example but you can keep a list of sound, and pick randomly without repetition like that:

    +System: On Start of layout
       -> Array: set size to (0,1,1)
       -> Array: push back soundA.wav on X axis
       -> Array: push back soundB.wav on X axis
       -> Array: push back soundC.wav on X axis
       -> Array: push back soundD.wav on X axis
       -> ...
    
    +On whatever
       local number randomIndex = 0
       -> System: randomIndex = floor(random(Array.Width))
       -> Audio: play sound Array.At(randomIndex)
       -> Array: delete at index randomIndex)

    The delete function of the array object delete the value at the index and shrink the array by 1 to fill the gap. So the Array.Width will decrease until you played every sound in the list.

  • I can work it out without array I think, but it would be a real pain (tonnes of conditions)

    I think a good start is to have a kind of conversion table.

    cardConversion.At(0,0) = "ace"
    cardConversion.At(0,1) = "hearts"
    
    cardConversion.At(1,0) = "ace"
    cardConversion.At(1,1) = "diamonds"
    
    ...
    
    cardConversion.At(52,0) = "king"
    cardConversion.At(52,1) = "spades"

    What would you use that for?

    Well the idea is that you would have all the card images in 52 frames of a card sprite in exactly the same order.

    And thanks to this cardConversion array you'll be able to know the rank of the suit of any given card through it's animation frame.

    cardConversion.At(card.AnimationFrame,0) will give you the rank of the card

    cardConversion.At(card.AnimationFrame,1) will give you the suit of the card

    Now you can just lay down the starting position of the cards in the layout.

    And you'll just have to find a way to randomize the animation frame of each card without duplication.

    But it might become a pain to maintain the deck itself.

    So maybe yeah, an array just for the shuffling of every cards,

    Then you distribute the card in this shuffled array by changing the frame of the cards laid out, and deleting the value in the array each time (with the delete function so your array shrinks at the same time) and then you'll be left with your randomized starting cards plus a cool deck array to cycle in (:

    Then it's just a matter of coding the rules of the game.

    like if you drop a card on a given column, check that the rank or the last card of the column (highest Y position)is the current card's rank + 1 and that the suit is the other color (you can try another kind of conversion table to answer this question or work it out with just conditions)

    Then valid the move or not.

    Same kind of thing to move the card on the 4 suit slots on the top right.

    So yeah you'll need array and some bits of good knowledges of C2, but no complex math (:

    So yeah good luck

    (An yeah, power bumping makes you look like a jerk, and also often makes people not willing to answer you... So be carefull)

  • I think if you want better performances you should work with arrays not objects. Unless you're not using a grid based graph (?) otherwise array is probably the optimal datastructure.

    But to answer your question, the "foreach ordered" on top of looping over all instance, probably runs a sorting algorithm before (which behind the scene probably compare each instance with each other at some point so you have like a hidden nested loop).

    Maybe should just do a simple foreach like that:

    +on whatever
        local number lowest = 99999 
        local number lowestUID = -1
    
        + system: foreach object
        + object: variable < lowest
            -> system: set lowest to object.variable
            -> object: set lowestUID to object.UID
         
        + object: pick by UID lowesUID
            -> do whatever
  • Oh new version is already up!

    Alright I tested the capx I provided and my good old maze capx, all is working super fine thanks (:

    (that won't stop me from continuing to torture these functions though mwahahahah!)

  • Ashley

    I can only imagine the complexity of that. Thanks for your effort (:

    I think functions can greatly increase the readability of a capx (and then teamwork), that's why I'm focusing on it these days and stress-test them.

    Thanks to them, I am now able to more easily separate chunks of event and avoid undesirable interactions (which makes modifying/extending/refactoring some events that much easier)

  • blackhornet

    Alright, thanks for the clarification. I must admit that I encountered this bug in a more complex situation (a maze generator) and it behaved as if the function stopped, but it could as well be due to wrong variable values (:

  • I was showing off my maze capx and then bam... broken.

    I was able to recreate the bug in a simple capx.

    Basically, if you still have stuff to do after a recursive call, well... it's ignored.

    Here's the simple capx.

    functionStopsOnRecursion.capx

    If you run the capx, nothing gets displayed.

    But if you put the

    Text: Append first&newline[/code:34f5l3k5]before the functionn call (event 3), it works as expected.Yann2012-12-09 02:10:13
Yann's avatar

Yann

Member since 31 Dec, 2010

Twitter
Yann has 5 followers

Connect with Yann