Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. creation of states throws warning every second time

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    creation of states throws warning every second time

    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      flachdachdecker last edited by flachdachdecker

      Newbie question:
      I have a simple JavaScript code to create and delete a "test" state:

      console.log("-----------------------")
      createState("test", 0);
      console.log(getState("test").val);
      setState("test", 4);
      console.log(getState("test").val);
      setState("test", 5);
      console.log(getState("test").val);
      deleteState("test");
      

      somehow - if fails every second time I start the script:
      fefc0f4b-361f-45cb-aac1-9e89260af2c1-image.png

      I am on js-controler 5.0.17 and JavaScript adapter 7.1.6. IObroker was fresh started. The test-state was not used by another script.

      Can you give me a hint what I'm doing wrong?

      paul53 1 Reply Last reply Reply Quote 0
      • paul53
        paul53 @flachdachdecker last edited by paul53

        @flachdachdecker
        Weshalb schreibt ein Flachdachdecker englisch?
        Die Funktion createState(id, init) wird asynchron ausgeführt, d.h. sie ist noch nicht fertig, wenn der Wert gleich darauf mit getState(id).val eingelesen wird. Das gleiche gilt für setState(id, val), die ebenfalls asynchron ausgeführt wird.

        F 1 Reply Last reply Reply Quote 0
        • F
          flachdachdecker @paul53 last edited by

          @paul53 weil ich dachte ich errecihe damit mehr potentielle Helfer 🙂

          Ich habe mir schon sowas gedacht, in der Doku gibts ja auch die entsprechenden async-funktionen. Nur - ich bin blutiger Anfänger und habe keine Ahnung wie man mit async umgeht.

          Hast du einen Tipp wie ich den code so umschreiben kann, dass er immer funktioniert?

          paul53 Homoran 2 Replies Last reply Reply Quote 0
          • paul53
            paul53 @flachdachdecker last edited by paul53

            @flachdachdecker sagte: code so umschreiben kann, dass er immer funktioniert?

            createState("test", 0, function() {
              log(getState("test").val);
              setState("test", 4, function() {
                log(getState("test").val);
                setState("test", 5, function() {
                  log(getState("test").val);
                  deleteState("test");
                });
              });
            });
            

            Manche nennen es "Callback-Hölle".

            F 1 Reply Last reply Reply Quote 1
            • F
              flachdachdecker @paul53 last edited by

              Super, viele lieben Dank! Das hat geholfen!
              Ein guten Rutsch!

              1 Reply Last reply Reply Quote 0
              • Homoran
                Homoran Global Moderator Administrators @flachdachdecker last edited by

                @flachdachdecker sagte in creation of states throws warning every second time:

                weil ich dachte ich errecihe damit mehr potentielle Helfer

                1:1000 anders herum 😁

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post

                Support us

                ioBroker
                Community Adapters
                Donate

                956
                Online

                31.8k
                Users

                80.0k
                Topics

                1.3m
                Posts

                3
                6
                224
                Loading More Posts
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes
                Reply
                • Reply as topic
                Log in to reply
                Community
                Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                The ioBroker Community 2014-2023
                logo