How do I fill slots?

0 favourites
  • 6 posts
From the Asset Store
An educational game for Fill in the Blanks. An easy to use template for developers to build larger games
  • Hey everyone,

    I'm completely new to construct2 and like to make litte game to learn and get used to it (yes, i also did the beginners tutorials )

    The game itself is kind of a "mastermind" typed game, you get a random code, try to solve it, and so on...

    So, the problem I currently have is:

    I have (or should have) an array of slots (fixed length) and an array of sprites (colors), when I click on one of the color-sprites it should create a new copy of the object in the "code-bar" on the next open slot and also write it into the array, unless there is no open slot left.

    How can i prevent the new object creation everytime i click on the color, and also set it to a new slot every time?

    How to even have dedicated "slot"-objects to add a color-sprite to?

    I'd appreciate every information on how to get this working how i think or some advice how to think it right to fit into a construct2 workflow

    Greetz,

    Dirty

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It;s very unclear to me what exactly it is you are asking..

    I guess what you'd like to do is add the color clicked to the array..

    so I guess you would have to know which row you are using

    for the first six colours set them to array =at(0,0) till arrayat(0,6)

    add one to a variable

    and the next will set to arrayat(variable,0) untill Arrayat(variable,6) and so on?

    Could probably all be done within one function.

  • Thanks for the reply, yes I don't know myself what i have to do for what i want.

    I know how to add the clicked color to an array, but I don't know how to create a new object for to be shown at the first slot.

    I had it this way:

    "black-pin"-object > on click > create new "black-pin"-object on image-point(0) of "slot1"-object & push "black" to array

    same for "white-pin"-object

    What I want:

    "someColor-pin"-object > on click > create new "someColor-pin"-object on image-point(0) of "slotX"-object & push "someColor" to array

    where "X" is just the next slot starting at 1

    So having a variable where i count the slots sounds well, but i need to get the number of the next slot in the action and I think string-chaining for variable names like in javascript doesn't work.

  • You've completely lost me here..

    If you are going to "push" the colors into the array, why not use the array as reference to create the visuals?

    I have no idea what string chaining is and why you would need it, it sounds like what you want to do is relatively easy.

    You should probably use the function object to create the action, for all actions are almost the same, only the variables change, so if you put these in the correct spot in the function it will all go as planned..

    Instead of creating at imagepoint 0 of the slotx object, why not create like this

    variable SlotX = 0

    variable SlotY = 0

    on black pin object pushed call function ColorPicked with parameter 0 is black

    On function ColorPicked

    • Array set at xy : x=SlotX - Y=SlotY value = function.parameter(0)

    --subevent

    -- If variable SlotX < 5

    --- set SlotX : SlotX+1

    -- If variable SlotX =5

    ---set SlotX : 0

    ---set SlotY : SlotY+1

    • call function Draw

    on function draw

    • destroy all sprites

    -array compare value at xy: 0,0 = black

    • create object blacksprite at x=100+100*array.CurX - y=100+100*array.Cury..

    bladiblah..

    Something like this should work..

    By the way instead of making a lot of different sprites (black, blue,red,whatever) wich have everything incommen exept for there color, I would choose to use animations or animationframes of 1 sprite.. that way you only have to set the frame or animation to the color desired and all that has to be created is the same sprite over and over..

    Youi get the drift..

    -- create

  • Thanks!

    Yes, I think a get what you mean. The reason why i'd like to have string-chaining is that i want to have something like slot+"array.curX".imagePoint(0) = new blacksprite; is it possible to store my "slot"-object into another object so i could say like slots[array.curX] = new blacksprite; ? I just like to have the pins relative to the slot than just set the x,y coordinate, so i'm save with screenresizing, layoutchanges and what not.

    thanks for the advice with animationframes, souds a lot better than having single sprites.

    greetz,

    Dirty

  • I really don't follow what you are saying..

    slot+"array.curX".imagePoint(0) = new blacksprite

    what is this supposed to mean or do?

    Why not just have an empty-slot sprite with animations for the filled slotsprites?

    all you'd have to do is set the animation to array.at(slotxnr,slotynr)

    if array at that place is zero set aninmationframe to zero.. (empty slot)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)