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

Get help using Construct 2

Post » Wed Apr 15, 2015 5:42 pm

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.
B
8
S
2
Posts: 110
Reputation: 923

Post » Thu Apr 16, 2015 9:35 am

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...
B
8
S
2
Posts: 110
Reputation: 923

Post » Thu Apr 16, 2015 9:51 am

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Apr 16, 2015 10:35 am

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?
B
8
S
2
Posts: 110
Reputation: 923

Post » Thu Apr 16, 2015 10:53 am

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Apr 16, 2015 11:33 am

The only reason I started this topic, was because, when I first tried to change the value of green.points by adding to it 2*green.points from pressing x2, didn't change anything in the 1st string. This is the only thing I am looking for. The only question I have. What expression to use, to be able to change green.points value ?

My command is:
On x2 pressed: Add green.points to green.points
On x2 pressed gain ( else ) subtract green.points from green.points
And doesn't change anything! Only to the global2, because there is only math, and one number created by adding all points from all objects.
But string 1 ( global 1 ) contains name also. in this way: green.name&green.points&green.weight.
When x2 is pressed, it doesn't add value to green.points. Why? This was my very first question.
How do I double the value of a variable which is already set to a String? The value of this variable it doubles, in the project, but this change doesn't apply to the string where it's initial value is set. Why?
B
8
S
2
Posts: 110
Reputation: 923

Post » Thu Apr 16, 2015 12:05 pm

So here's how I would do it:

capx

(Not completely true, because I would try to prevent the text-update being performed every tick, but for now it will do)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Apr 16, 2015 12:42 pm

WOW....this looks gorgeous... it is totally different from the tactics I started using, and it is a couple of times shorter...
And why would you prevent using System;Every tick? What role it has inside this events?
B
8
S
2
Posts: 110
Reputation: 923

Post » Thu Apr 16, 2015 12:52 pm

I don't really like the program having to perform actions every tick, that only have to be performed every time some information changes.
So usually I would add some events to only perform those actions when needed...

But I only had an hour to spare, so this should do..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Apr 16, 2015 12:58 pm

I will try to implement it now in my project. I am very thanful to you, @LittleStain .. I will come back with more thanks when I roll out this stuff and see it working.
B
8
S
2
Posts: 110
Reputation: 923

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: imhotep22, plinkie and 7 guests