stats calculator how would I do this.

0 favourites
  • 5 posts
  • Hello everybody,

    I want to take 2 numbers.

    say I have 7 lines with 3 numbers

    (stat 1) (Stat2) and (fixed number)

    (stat 1) (Stat2) and (fixed number)

    (stat 1) (Stat2) and (fixed number)

    (stat 1) (Stat2) and (fixed number)

    (stat 1) (Stat2) and (fixed number)

    (stat 1) (Stat2) and (fixed number)

    (stat 1) (Stat2) and (fixed number)

    I want the fields fillable by the user.

    so if stat1 =78 and stat2=55 arrange and output fixed number

    so if stat1=85 and stat2=25 arrange and output fixed number

    I want to compare the two fields against their fields

    then arrange them by highest and output fixed number in order of highest to lowest for stat1 and stat2.

    thanks in advance for any thought or ideas on how to create this. Jeremy C.

  • see the textbox tutorial: https://www.scirra.com/tutorials/624/te ... le-textbox

    Let's go slowly for what you wanna do. First, let's just have only this:

    (stat 1) (Stat2) and (fixed number)

    one line and 3 numbers.

    For stat 1 and stat 2, you can use TextBoxes there. For the fixed number, you can use text object. These are taught in the link above.

    Also, from the tutorial above, you also learn how to treive the value from the textbox. If you have two textbox objects, for example, TextBox1 and Textbox2, you can refer to the texts inside the textboxes with TextBox1.text and TextBox2.text.

    For the sake of simplicity, in the event sheet, you can use "every tick : set text object's text to int(TextBox1.text) + int(TextBox2.text) .

    This will make it so the value of text object will be set to 2 values of the Textboxes being added up every tick.

    Do you follow everything so far? If so, I will proceed for 7 lines just like you want.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • see the textbox tutorial: https://www.scirra.com/tutorials/624/te ... le-textbox

    Let's go slowly for what you wanna do. First, let's just have only this:

    (stat 1) (Stat2) and (fixed number)

    one line and 3 numbers.

    For stat 1 and stat 2, you can use TextBoxes there. For the fixed number, you can use text object. These are taught in the link above.

    Also, from the tutorial above, you also learn how to treive the value from the textbox. If you have two textbox objects, for example, TextBox1 and Textbox2, you can refer to the texts inside the textboxes with TextBox1.text and TextBox2.text.

    For the sake of simplicity, in the event sheet, you can use "every tick : set text object's text to int(TextBox1.text) + int(TextBox2.text) .

    This will make it so the value of text object will be set to 2 values of the Textboxes being added up every tick.

    Do you follow everything so far? If so, I will proceed for 7 lines just like you want.

    Yes I am with you so far. and as for doing it that way there are 4 numbers as Fixed number is set by user and just need to be displayed in order of stat1+stat2= stat object if stat object is higher arrange and display fixed number.

  • The above post is a naive implementation and it uses 2 TextBox objects. (TextBox1 and TextBox2) If you have 20 TextBoxes, having TextBox1, TextBox2 up to TextBox20 would work but it is ugly. You could go naive and create them like TextBox_Line3_Column1, Textbox_Line3_Column2 and Text_Line3. This works... but if you have to create 100 of lines, creating 100 lines manually would be hellish work.

    If your requirement is just that or if it is unlikely to change later, you can just go with the paragraph above.

    A more practical approach to iteration would be to have just 1 TextBox object, create many instances of them (copy and paste them) and refer to them using for loop and variables. The same goes with the Text object.

    So instead, for the 7 lines, what I would do is to create a variable for the textbox and text object. Let's call it "LineNumber". Once you arrange those TextBoxes and Texts on your layout to be in the correct order, you set LineNumber for each TextBox and Text instance accordingly to the line they are on. For example, line 1 instances have LineNumber set as 1, etc. For the textbox instances, you will also need another variable called "column". For the Textbox instances on column 1, give this value of 1. Do the same for Textbox instances on column 2 but give them value of 2.

    In the event sheet, you can do something like this:

    global variable sum = 0

    for i = 1 to 7,

    set sum = 0

    TextBox of variable Column 1 and LineNumber i: add int(TextBox.text) to sum.

    TextBox of variable Column 2 and LineNumber i: add int(TextBox.text) to sum.

    Text of LineNumber i : set text to global variable sum.

  • The above post is a naive implementation and it uses 2 TextBox objects. (TextBox1 and TextBox2) If you have 20 TextBoxes, having TextBox1, TextBox2 up to TextBox20 would work but it is ugly. You could go naive and create them like TextBox_Line3_Column1, Textbox_Line3_Column2 and Text_Line3. This works... but if you have to create 100 of lines, creating 100 lines manually would be hellish work.

    If your requirement is just that or if it is unlikely to change later, you can just go with the paragraph above.

    A more practical approach to iteration would be to have just 1 TextBox object, create many instances of them (copy and paste them) and refer to them using for loop and variables. The same goes with the Text object.

    So instead, for the 7 lines, what I would do is to create a variable for the textbox and text object. Let's call it "LineNumber". Once you arrange those TextBoxes and Texts on your layout to be in the correct order, you set LineNumber for each TextBox and Text instance accordingly to the line they are on. For example, line 1 instances have LineNumber set as 1, etc. For the textbox instances, you will also need another variable called "column". For the Textbox instances on column 1, give this value of 1. Do the same for Textbox instances on column 2 but give them value of 2.

    In the event sheet, you can do something like this:

    global variable sum = 0

    for i = 1 to 7,

    > set sum = 0

    > TextBox of variable Column 1 and LineNumber i: add int(TextBox.text) to sum.

    > TextBox of variable Column 2 and LineNumber i: add int(TextBox.text) to sum.

    > Text of LineNumber i : set text to global variable sum.

    I see where your going with that. I will play with the concept on my next day off.

    Once I finish the project I will post a link to what I am trying to create.

    I am keeping some of the details under wraps as to many of the same app is never a good thing.

    Thanks for all the help. Jeremy C.

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