So,. a short explanation what i want:

If i press a button, i pick one out of 31 items over the pick_random() function. That works and everything is fine, except of getting that item
and be able to change it's float value. ? I can do that if the item is defined directly, you find the details on the screenshot.

First i tried to remove an item of he array, but it messes up the pick_random() and nothing will be picked anymore. So i just want to change it's values.

Thanks to everyone who's spending time here.

How are you?

Ask this because i don't know how to delete a poll XD

Better than you'll0%
Noones business guys0%
Asking myself since last week0%
If not bad not so bad i guess100%
  • xyz replied to this.

    Those lines that have <- on the right should be causing errors, because that's not valid syntax.
    Comments should begin with #.

    Please explain the right side of line 87.

    That error message does not make sense, since I don't see a call to size().

      Gaming911

      var i = randi_range(0, array.size() - 1)
      array[i] = value

        DaveTheCoder Well, obiously this seems to be to complicated then, :

        First: of course i added the comments afterwards for the question.
        Second: That is the information for a Label, it displays the actual value of the picked array. Like in the game you see: "instance" : its value
        Third: Sorry that i didn't mentioned to ignore the error. It was still shown after i tried something with size().

        xyz Thanks but I think that is not what i am looking for,

        example:

        var germany = 1.0
        var usa = 1.1
        var...
        var...

        var addstrength = [germany,usa, ..., ...,]

        if Input.is_action_just_pressed("X"):

        (i want to get the "item for example germany") wich is randomly picked before

        item(germany) = 0 or just delete it from addstrength.

        • xyz replied to this.
          • Edited

          Gaming911 Thanks but I think that is not what i am looking for,

          That's exactly what you were asking; how to change the value of a randomly picked element in an array.

          Basic types such as int or float are always passed and assigned by value, not by reference. You can't put a reference to a float variable into an array or into another variable. You can just copy its value.

          So maybe describe what's your final goal with this. There could be another way to achieve it.

            20 days later

            xyz

            First, sorry for the late reply, and thanks for your answer!

            Ok, i thought about it again, aaaaaaand :
            if i do know the item of my array, for example "germany" again, well this item has a value of 1.0 .
            But how do i type something like this:

            for i in array:

            var "germany" = i

            array[germany] += 0.2

            So that the value (var germany = 1.0) now has a value from: 1.2 . Do i lack of fundamental understanding somewhere?

            ? Everything i try gives the error: Invalid get index '0' (on base: 'float').

            The final goal: i need this value, because it is part of a time for an action you take during my game. 1.0 is standard and 1.2 is a multiplicator.
            And using an array is so much more compact than writing a book for a simple thing i need here.

            • xyz replied to this.
              • Edited

              Gaming911 As I said, you can't have a reference to a built in type variable as those types are always passed/assigned by value.
              Just change the variable directly or use a dictionary:

              var dict: Dictionary = { "germany": 1.0, }
              dict["germany"] += 0.2