0 Favourites

Is this possible in C2? How?

  • IS THIS POSSIBLE HERE IN C2? HOW? I MADE A RANDOM NUMBER CAPX BUT I FIND IT HARD TO THIS FLOW.. I HOPE YOU CAN HELP WITH A CAPX. THANKS.

  • IS THIS POSSIBLE HERE IN C2? HOW? I MADE A RANDOM NUMBER CAPX BUT I FIND IT HARD TO THIS FLOW.. I HOPE YOU CAN HELP WITH A CAPX. THANKS.

    You can do it in several ways, either with a list, array, dictionary or from a file etc.

    To do it with a list (Which is the easiest to explain I think), you can use "Add to list" and then insert a String. The list will automatically give each item an index, starting at index 0.

    0: James

    1: Robert

    2: Jack

    3: ... so on

    The String you insert could come from a Textbox and you can retrieve the name from the list at an given index using get "ItemTextAt" and you can change the index that you want to get with an "Int(Random(List.Itemcount))" to make it choose a random index from the list.

    Here is an example:

    https://dl.dropboxusercontent.com/u/109921357/Add%20and%20get%20names/Add_and_get_names.capx

  • Thank you for the reply pls help me as I am lost with my events.. as seen below..

  • >

    > IS THIS POSSIBLE HERE IN C2? HOW? I MADE A RANDOM NUMBER CAPX BUT I FIND IT HARD TO THIS FLOW.. I HOPE YOU CAN HELP WITH A CAPX. THANKS.

    >

    You can do it in several ways, either with a list, array, dictionary or from a file etc.

    To do it with a list (Which is the easiest to explain I think), you can use "Add to list" and then insert a String. The list will automatically give each item an index, starting at index 0.

    0: James

    1: Robert

    2: Jack

    3: ... so on

    The String you insert could come from a Textbox and you can retrieve the name from the list at an given index using get "ItemTextAt" and you can change the index that you want to get with an "Int(Random(List.Itemcount))" to make it choose a random index from the list.

    Here is an example:

    https://dl.dropboxusercontent.com/u/109921357/Add%20and%20get%20names/Add_and_get_names.capx

    First of all, Thank you for the reply and sample capx. But I hope you can help me as I got lost as Im doing my codes in the events.

    Im using a global variable for the random number and I find it hard to connect the random number and the list .. is this possible or my coding is just complicated? or maybe there is much more simple logic than what im doing? Thanks again for the future help..

    https://www.dropbox.com/s/adjeivnm7xdph ... .capx?dl=0

  • Yeah you are mixing up things.

    If you look in my Capx I use a functionality that allow you to extract the text at a given index. This index goes from 0 to the number of items In the list. So you don't need a global variable its already being taken care of by the list internal index.

  • You should be using an Array. That is your missing link. You can make this list work using List.IndexOf, etc. But an Array object has more functionality.

  • You should be using an Array. That is your missing link. You can make this list work using List.IndexOf, etc. But an Array object has more functionality.

    Thank you for the advice but Im not really good in coding. Can you give me sample capx using arrays? Thank you ..

  • Yeah you are mixing up things.

    If you look in my Capx I use a functionality that allow you to extract the text at a given index. This index goes from 0 to the number of items In the list. So you don't need a global variable its already being taken care of by the list internal index.

    In your capx, Is it possible that the number text and the name text will appear separately. Random Number at the top then the Name at the bottom..

  • > Yeah you are mixing up things.

    >

    > If you look in my Capx I use a functionality that allow you to extract the text at a given index. This index goes from 0 to the number of items In the list. So you don't need a global variable its already being taken care of by the list internal index.

    >

    In your capx, Is it possible that the number text and the name text will appear separately. Random Number at the top then the Name at the bottom..

    Yeah you would have to modify it a little, but you can get the index number of a selected name as well or you could store the random index number in a local variable first which you then use to get the name as well as the number you want to place in the separate textbox.

  • >

    > > Yeah you are mixing up things.

    > >

    > > If you look in my Capx I use a functionality that allow you to extract the text at a given index. This index goes from 0 to the number of items In the list. So you don't need a global variable its already being taken care of by the list internal index.

    > >

    >

    > In your capx, Is it possible that the number text and the name text will appear separately. Random Number at the top then the Name at the bottom..

    >

    Yeah you would have to modify it a little, but you can get the index number of a selected name as well or you could store the random index number in a local variable first which you then use to get the name as well as the number you want to place in the separate textbox.

    I appreciate your tips and the effort to reply but I hope if its ok with you that you can modify my capx a little. I find it hard to find ways. even using arrays, etc. But I will try to do it .. thanks..

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • NAME: Set Text: List2.ItemTextAt(RANDOMNUMBER)[/code:1bu2f5hl]
    
    Except that you will occasionally get null, since you are using SMALLEST to BIGGEST+1, and BIGGEST and BIGGEST+1 will never exist, because the List2 indices start at 0.
    
    You can condense all of that down to one row though:
    
    [code:1bu2f5hl]NAME: Set Text: List2.ItemTextAt(floor(random(List2.ItemCount)))[/code:1bu2f5hl]
    Like this:
    [img="https://s23.postimg.org/x1wuang23/image.jpg"]
    Note: The floor might mitigate the index issue at the top.  So it might be round(random(List2.ItemCount-1) or floor(random(List2.ItemCount)) try them both.
  • I appreciate your tips and the effort to reply but I hope if its ok with you that you can modify my capx a little. I find it hard to find ways. even using arrays, etc. But I will try to do it .. thanks..

    Here is a modified version.

    https://dl.dropboxusercontent.com/u/109921357/Problem_2/Problem_2.capx

  • This is a good tutorial for arrays. It even shows an example of the insertion that you are trying to achieve.

    https://www.scirra.com/tutorials/307/ar ... ers/page-1

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
Spriter/C2 - Spriter 2 Teaser!
1,800 322,269
tarek2's avatar
tarek2
Unread sticky
763 305,704
asikanddestroy's avatar
asikanddestroy
Unread hot topic
0 Favourites
Your C2 tests
566 243,742
thisisblogs's avatar
thisisblogs