How do I create x amount of objects (global variable)

0 favourites
  • 8 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hi Yall!

    I have a question.

    As seen in very much games lately i am trying to create a answer system.

    I have done this before with a complete keyboard that works fine but this time i want to make it different.

    I want to give the person some random letters mixed with letters you can use for the answer.

    Now, i want to create a x amount of objects because i want to show the length of the answer.

    Example:

    Now, the little empty spaces in the image should be the amount of the answer.

    So if i have a answer "Construct" i need to create 9 of those objects.

    And if that isn't enough they need to be perfectly centered.

    Can any one help me with the best technique to do this?

    Thanks in advance!

  • maths and stuff

    Firstly you will want a variable for the spacing between the objects.

    Then, you're going to want a for loop, which goes from 1 to the length of letters in the word. (len() system expression). Then on each loop spawn a new object with the X coordinate of "(LayoutWidth/2) + (spacing* Object.width*(loopindex-((len(word)+1)/2)))"

    the spacing variable usually works best between 1 and 2

  • Try this...

    [attachment=0:1ibumqf9][/attachment:1ibumqf9]

    You can write any answer and hit enter or click the button to update the slots.

    Attention: In this example the registration point for the slots is top-left (0,0) not the default registration, which is centered. If you preffer a centered registration, remember to add half the width of a slot to the firstX variable.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Wow guys thanks! Both work like a charm!

    I got so many more things to learn!

    Great thanks!

  • Hi Guys i found out i have one more question.

    After this i still don't know how to create random letters.

    Well, i know how to create random letters but i don't know how to make sure the letters are included that are needed to create the answer.

    Can any one help me out with that one?

    As seen in the image on my first post ( the A,W,A,A,A,A,A,A,A buttons ).

    I will take the word "Construct" for example again.

    I have 18 Letters/Buttons. These letters have to be random but the letters C,O,N,S,T,R,U,C,T have to be included in those letters.

    So in this case i need the letters construct and 9 other random letters ( A to Z ).

    The letters construct is actually a global variable.

    Sorry for all these questions but i am pretty noob at that kind of things !

    Thanks in advance!

  • Allardje:

    I made you a simple demo of the principle...

  • Here...

    [attachment=0:3kxbym9a][/attachment:3kxbym9a]

  • Hey i actually integrated the script brunopalermo ,

    I pop up one question tho.

    While working on the answer system ( so if you press a letter button that letter will appear in the answer slots ) i am not sure how to.

    What i did is creating a text object on every "letter slot". These letters will be filled in with the right letter and will become visible if a right letter is pressed.

    That part would be fine to create i think i can manage it but somehow i want to cut the answer in letters just like you do when creating the right letters and random letters.

    Though my: find(uppercase(answer),mid(ALPHABET,loopindex,1)) won't work to get all letters.

    This is what it looks like atm:

    This is what i did. As you can see i tried using it the same way as it creates the letter slots:

    As you can see below creating the amount of "letters" is correct but my code isn't:

    This works for the letter slots and the amount of letters but not for the text itself: find(uppercase(answer),mid(ALPHABET,loopindex,1))

    Somehow the letters appear as 0 and -1.

    Can you please help me with that line of code? I think i'm heading the right direction but my line isn't completely correct.

    Thanks!

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