Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [Gelöst] Function erstellen

    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

    [Gelöst] Function erstellen

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

      var SL, SR, PosL, PosR;
      function MeineFunktion () {
      PosL = getState('tahoma.0.devices.Markisse_Links.states.core:DeploymentState').val;
              if (PosL > 0) {
                  SL = "Ausgefahren"
                  setState(idNr, 2);//AUSGEFAHREN 
              } else {
                  SL = "Eingefahren"
                  setState(idNr, 1);//EINGEFAHREN
              };
      };
      
      M 1 Reply Last reply Reply Quote 0
      • M
        michihorn @JohGre last edited by

        @JohGre Wie kann ich dann den Wert der Funktion weiter verwenden?

        JohGre 1 Reply Last reply Reply Quote 0
        • JohGre
          JohGre @michihorn last edited by

          @michihorn
          Außerhalb der Funktion(), innerhalb des Scripts überall. Außerhalb des Scripts nur über ein State Objekt.

          M 1 Reply Last reply Reply Quote 0
          • M
            michihorn @JohGre last edited by

            @JohGre Also meine Funktion heißt "Status", wie lese ich den Wert der Funktion? var x=Status()?

            1 Reply Last reply Reply Quote 0
            • JohGre
              JohGre last edited by

              //Deklaration der Funktion
              function MeineFunktion () {
              var SL, SR, PosL, PosR;
              PosL = getState('tahoma.0.devices.Markisse_Links.states.core:DeploymentState').val;
                      if (PosL > 0) {
                          SL = "Ausgefahren"
                          setState(idNr, 2);//AUSGEFAHREN 
                      } else {
                          SL = "Eingefahren"
                          setState(idNr, 1);//EINGEFAHREN
                      };
              //Return Wert
              return SL;
              };
              
              //Aufruf der Funktion
              var JalosienStatus = MeineFunktion();
              

              mit return kannst du einen Wert aus einer Funktion an den Aufrufer zurückgeben

              M 1 Reply Last reply Reply Quote 0
              • M
                michihorn @JohGre last edited by

                @JohGre Dankeschön das passt

                1 Reply Last reply Reply Quote 0
                • JohGre
                  JohGre last edited by

                  Kein Problem, wenn gelöst bitte Thread kennzeichnen einfach [gelöst] im Titel vorne anfügen

                  M 1 Reply Last reply Reply Quote 0
                  • M
                    michihorn @JohGre last edited by

                    @JohGre Ein Frage wäre noch, kann eine Funktion zwei Rückgabewerte haben?

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

                      @michihorn sagte:

                      kann eine Funktion zwei Rückgabewerte haben?

                      Nein, man kann aber ein Objekt zurück geben.

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

                        @paul53 Ok Danke

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

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        699
                        Online

                        31.8k
                        Users

                        80.0k
                        Topics

                        1.3m
                        Posts

                        javascript
                        3
                        11
                        274
                        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