SOLVED///How do I add a value to a inst. var from a string?

0 favourites
From the Asset Store
Add SubRip (SRT) subtitles to your videos in Construct 3
  • I have a global variable where certain numbers and texts are added from different actions like:

    Set Global1 to Global1&object1.name&object1.points&object1.weight etc...

    In the global they show up like this:

    NAME 12 50

    When I create an action like:

    Object2.points Add to Object1.points no changes happen Object1 values from the Global1.

    Another set of actions are like that:

    Add Object1.points to Global2 and It is working good. Numbers are calculated as totals. But how do I make them to be added to the first global as well? They do not add... How do I make math work on values already written in the 1st string? without having to reset it...

    In simple words, how to add a value to an instance variable who's value is already in a string and make this change in that value in the string , not only to the object in general? I just need to keep their order, during adding values, that's why I am asking such a thing...

  • Could you try explaining why you want to do this this way.

    It really seems to me you'd like an explanation on how to do things in a not very effective way.

    Setting a string variable can be done in the same way as setting a text-object's text.

  • It is not about Setting a string, but Adding a value. I am doing math there... Array is a much better solution, but I will have to confess I am a total incompetent in them. I am working on a project now and want to finish it's first version in any way. After that I am planning to study the Array functions and simplify my work. But the start doesn't allow me to pause now... I am just a learner now.

    Here is the simple capx with a meaningful explanation:

    drive.google.com/file/d/0B09lLdP7JoIAZFY4clA4V1lRV3c/view?usp=sharing

  • Anybody, please?...

  • I'm not sure if I'm right, but it seems to me you are trying to do mathemetics while setting the string.

    I would choose to seperate numbers from strings and first perform the mathematics and use the the string to display the result.

    This would also give you better control over the numbers if you were to change them.

    something like:

    Add a new objectvariable and call it Totalpoints

    if x2 set totalpoints to 2*points

    if totalpoints is not 0 use it in the string

  • If you could see, I already a second string where math is being performed, with a total of points from pressed objects. But in the first string it is a set of Sprite.names but each followed by it's particular score. And when x2 is pressed under one object, not only it's score is added to the second string, doing the total, but also replaces the value in the first string, of that object. It is not possible?

  • I did see the capx.

    points is a number variable and not a text variable.

    points is also calculated before setting the text to points, which is the way I suggested above.

    So like I said:

    Calculate the value in a number variable and use the calculated value in the string.

    You are already doing that with points, so why not with the other variables?

  • so...you have...

    TEXT 1: varable name (Green)___________TEXT 2: Global points(30)

    ..............variable points (30)

    on Touchet "2X" you add variable points(30) only to Global points...

    so...you have...

    TEXT 1: varable name (Green)___________TEXT 2: Global points(60)

    ..............variable points (30)

  • I undersrtand the logics... but I can't quite reinterpretate them now... I don't know what actions to use to make Global points be added to a specific object value in another string. I will play now with the events, and try to figure it out...

  • pressing x2 doesn't double all the numbers from the Number Global. it doubles only the value of the selected object. Maaan, I am so stuck now )) I hope I will figure it out , as it is the last step of my whole project.

  • NO, I do not get to the point... anyhow! I've tried ten different combinations. The most logical was :

    Add Global.points to Global1 but it just ads the whole number from the second global into the first one, and it is totally not what I am looking for.

    Let me try to ask in a different way.

    So, we do it that way:

    On touched Button1 - Green.points are set to Global1 ( Green; 30; )

    Green points are added to Global2 ( 30 )

    On touched x2:

    Global1 changes to - (Green-x2; 30)

    Gloabl2 to - (60)

    On touched Button2:

    Blue.points are set to Global1 ( Green-x2; 30; Blue; 25; )

    Blue.points are added to Global2 ( 85 )

    On touched x2 under Blue we get:

    Global1 changes to- ( Green-x2; 30; Blue-x2; 25 )

    Global 2 changes to - ( 110 )

    So, what command do I have to insert for the first global to suffer changes in the numbers variables? And become

    ( Green-x2; 60; Blue-x2; 50 )

    I don't believe Javascript doesn't allow such a thing!

    If I create a command like:

    Set to Global1 Global1&Green.points&Global2 it will add after Green.points the total points from the Global2. I need to be added only the called amount....and not be placed after the texts already writen there, but replace the initial number.

    Can anybody write a short code here for the noob of me to understand where I get wrong? Please.

  • No, guys, really, I need a small assistance here... please...

    It doesn't work the method you said.

    I changed in first string like this:

    Set name to name&Green.Variable1&points ( points is the global variable where total is created )

    On touched Button1

    String1 = Green; 30; String2 = 30;

    On touched x2 - Add green.points to Points

    String1 = Green-x2; 30; String2 = 60;

    So even if Global points is set as Second text in String 1 , no changes are made to its numbers on touched x2. What is this? I am starting to get crazy...

  • On x2 you are adding 30 points to global2, but you aren't adding points to green.points.

    green.points stays the same so in the string it is still 30.

    one way to solve this is to change green.points the same way you change global2

    another way would be to add a totalpoints variable to green and set it to green.points when button touched and to 2*green.points when x2 touched.

    Instead of using green.points in your string you could use green.totalpoints.

  • There will be absolutely no difference between the total.points and green.points |

    They both receive the amount which is called bu pressing button. And they both are a number variable of the same object.

    In my project, I have 25 object which will need to be added to this string. Each object has a .name , .weight and .points variables.

    In one string, it is easy, only the total of all added is shown. In another, the total of weight. But each time their name is pressed, they are added into the first string, in the pressed order. A and each time, x2 is pressed, in the last 2 strings, the number is added to the total, and it is very simple. But In the first string, the value before x2 remains, and it is not nice at all. It is confusing. The way you last described, will it have the power to make any change to the value of each element in particular from the first string? The only way that works, is create a global variable for each element and create a different string in front of each name placed in the 1st string.... it is a week of working, and it doesn't seem efficient enough.

    Is there any command, expression or whatever it is called, that can do this? :

    On button press - Add green.points to Global2

    Add ( or Set ) green.points to Global1

    On x2 pressed - Add green.points to Global2 ( creates total of all points of all objects added to this string )

    Add ( or set ) green.points to Global1 only to the green.points variable? Replace it!

    What is the difference between points and totalpoints? Why is it so hard to change a number.variable inside a string? Because it contains text?

    Isn't there any command/expression that locates this number.variable inside the string and changes it to what I say?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok..

    What I said wouldn't take a week.

    You don't need global variables, because like I tried to explain using instance variables would work.

    I don't now what total.points is, I was talking about green.points and green.totalpoints.

    If you set green.totalpoints to 2*green.points there will be a difference, because 2*something is different from 1*something, unless the something is 0.

    Let's recap

    -you are changing the value of global2 on x2 pressed

    -you are NOT changing the value of green.points on x2 pressed

    • the string displays green.points
    • the value in the string doesn't change, because the value of green.points doesn't change.

    solution:

    either change the value of green.point on x2 pressed.

    or change the value of another variable and have the string display that variable, only using green.points as a number to calculate the value of the new variable.

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