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
  • 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?

  • 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)

  • 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?

  • 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 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.

  • Removed the every tick and added a function to only update on events that change values.

    Updated Capx

    I could have overlooked something, but think it should work..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It is 10 times difficult than my technique and when I started implementing yours in my project, I got chaos and texts not showing...

    I dont have functions, loops and object instances...

    But Iam trying to understand what is going on in your capx..

    Give me your e-mail to send you my full capx and you will understand what level of knowledge I have in c2

  • Like I said, this is the way I would do it.

    I've seen your capx and understand that to you my way might seem complicated.

    I only had a short amount of free time, so I didn't add comments.

    What I think you might have missed trying to copy/replicate what I did is the "container"

    By putting all related objects into a container, there is no need to specify which instance should respond, for they are connected.

    The function was added later, only because of my personal dislike for events running every tick if not completely nescessary..

  • This container make texts be created each time a new color is created. Yes, I missed this at the first view, now I noticed.

    But even this doesn't clear my mind upon the text appending and other stuff. The only thing I am trying to figure out is what exact event/action changes the sprite.totalweight in Text4. When I understand this, I will be able to accomplish my final step of the project.

    You capx is brilliant.

  • the value of sprite.totalweight is changed in the events of clicking either the button or the x2.

    Text4 only displays the current value of sprite.totalweight.

  • It also displays color and KG. In my project is the same, but the number does not change. This is the main reason such a big thread started

    I am trying to understand the logics of this result.

  • if you want to replace some parts of the StringVariable...you need to know Index and Separator...

    ..lets say your StringVariable looks like:

    Green

    50

    20p

    so...

    Green=index 0 ;50=index 1 ;20p=index2

    and Separator is "newline"

    capx:

    http://s000.tinyupload.com/index.php?fi ... 5113411336

  • that's a very nice example and it's pretty close to what I have. I tried to create the else event for substracting, but it is not working. is there a special command for indexes?

  • can u please tell me how?

  • Ok..let's try one more time...step by step

    in capx im upload ..in my previue post...

    ..what you want to happen next?

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