Hallo, ich versuche einen countdown in einer sub auszuführen.
Leider bekomme ich immer Fehler wegen nicht deklarierter Variablen ($d).
Mit Instanzvariabler ($_d) funktioniert zumindest die sub, doch leider OHNE wirkliche Parameterübergabe.
Vielen Dank für Tips.
[code]define di_CountDown DOIF subs {\
sub counter {\
my ($d) = @_;; ##klappt nicht\
set_Reading("Test",$d);; ## test Parameterübergabe i.O.\
set_Exec("countdown1",1,'set_Reading ("count1",$d-1-$count,1)','$count<$d');;\
## set_Exec("countdown1",1,'set_Reading ("count1",$_d-1-$count,1)','$count<$_d');;\
}\
}\
\
{\
if ([$SELF:mybutton] eq "off") {\
set_Reading("test","off",1);;del_Exec ("countdown1");;\
} \
elsif \
([$SELF:mybutton] eq "on") { \
$_d=10;; ## diese Kombination\
counter();; ## funktioniert\
\
counter (10);; ## mit Parameterübergabe leider nicht\
\
## set_Exec("countdown1",1,'set_Reading ("count1",$_d-1-$count,1)','$count<$_d');;\
}\
}\
attr di_CountDown DbLogExclude .*
attr di_CountDown readingList mybutton
attr di_CountDown room DOIF_Labor
attr di_CountDown setList mybutton:on,off
attr di_CountDown uiState {package ui_Table}\
ring([$SELF:count1],0,10,0,120,"Seconds",150,undef,0)|
attr di_CountDown webCmd mybutton
# CFGFN
# DEF subs {
# sub counter {
# my ($d) = @_; ##klappt nicht
# set_Reading("Test",$d); ## test Parameterübergabe i.O.
# set_Exec("countdown1",1,'set_Reading ("count1",$d-1-$count,1)','$count<$d');
# ## set_Exec("countdown1",1,'set_Reading ("count1",$_d-1-$count,1)','$count<$_d');
# }
#}
#
#{
#if ([$SELF:mybutton] eq "off") {
# set_Reading("test","off",1);del_Exec ("countdown1");
# }
#elsif
# ([$SELF:mybutton] eq "on") {
# $_d=10; ## diese Kombination
# counter(); ## funktioniert
#
# counter (10); ## mit Parameterübergabe leider nicht
#
# ## set_Exec("countdown1",1,'set_Reading ("count1",$_d-1-$count,1)','$count<$_d');
# }
#}
#
# FUUID 66c717d5-f33f-2206-4fb9-a1efcc3355635a39
# MODEL Perl
# NAME di_CountDown
# NOTIFYDEV di_CountDown,global
# NR 1104
# NTFY_ORDER 50-di_CountDown
# STATE initialized
# TYPE DOIF
# VERSION 28546 2024-02-23 20:11:05
# eventCount 811
# Helper:
# DBLOG:
# mode:
# DBLogging:
# TIME 1724323797.9014
# VALUE enabled
# OLDREADINGS:
# READINGS:
# 2024-08-22 17:21:42 Test 10
# 2024-08-22 17:21:42 block_01 executed
# 2024-08-22 17:13:00 count1 0
# 2024-08-22 17:21:42 e_di_CountDown_mybutton on
# 2024-08-22 17:21:42 error eval condition: Global symbol "$d" requires explicit package name (did you forget to declare "my $d"?) at (eval 343850) line 1.
#
# 2024-08-22 17:21:34 mode enabled
# 2024-08-22 17:21:42 mybutton on
# 2024-08-22 17:21:34 state initialized
# 2024-08-22 17:21:39 test off
# Regex:
# accu:
# bar:
# barAvg:
# collect:
# cond:
# di_CountDown:
# 0:
# mybutton ^di_CountDown$:^mybutton:
# uiState:
# di_CountDown:
# di_CountDown_uiState_c_0_0_0_0:
# count1 ^di_CountDown$:^count1:
# condition:
# 0
#if (::ReadingValDoIf($hash,'di_CountDown','mybutton') eq "off") {
# set_Reading("test","off",1);del_Exec ("countdown1");
# }
#elsif
# (::ReadingValDoIf($hash,'di_CountDown','mybutton') eq "on") {
# $hash->{var}{d}=10; counter();
# counter (10);
# }
#
# helper:
# NOTIFYDEV di_CountDown,global
# event mybutton: on
# globalinit 1
# last_timer 0
# sleeptimer -1
# triggerDev di_CountDown
# triggerEvents:
# mybutton: on
# e_di_CountDown_mybutton: on
# error: eval condition: Global symbol "$d" requires explicit package name (did you forget to declare "my $d"?) at (eval 343849) line 1.
#
# Test: 10
# error: eval condition: Global symbol "$d" requires explicit package name (did you forget to declare "my $d"?) at (eval 343850) line 1.
#
# block_01: executed
# triggerEventsState:
# mybutton: on
# e_di_CountDown_mybutton: on
# error: eval condition: Global symbol "$d" requires explicit package name (did you forget to declare "my $d"?) at (eval 343849) line 1.
#
# Test: 10
# error: eval condition: Global symbol "$d" requires explicit package name (did you forget to declare "my $d"?) at (eval 343850) line 1.
#
# block_01: executed
# internals:
# perlblock:
# 0 block_01
# ptimer:
# countdown1:
# cond $count<$d
# count 0
# name countdown1
# sec 1
# subname set_Reading ("count1",$d-1-$count,1)
# hash:
# readings:
# all di_CountDown:mybutton
# trigger:
# uiState:
# dev di_CountDown
# header
#<table uitabid='DOIF-di_CountDown' class=' wide uiStatedoif doif-di_CountDown ' style='border-top:none;'>
# package package ui_Table;
# reading count1
# table:
# 0:
# 0:
# 0:
# 0 package ui_Table;::DOIF_Widget($hash,$reg,'di_CountDown_uiState_c_0_0_0_0',ring(::ReadingValDoIf($hash,'di_CountDown','count1'),0,10,0,120,"Seconds",150,undef,0),"")
# tc:
# td:
# 0:
# tr:
# uiTable:
# var:
# d 10
#
setstate di_CountDown initialized
setstate di_CountDown 2024-08-22 17:21:42 Test 10
setstate di_CountDown 2024-08-22 17:21:42 block_01 executed
setstate di_CountDown 2024-08-22 17:13:00 count1 0
setstate di_CountDown 2024-08-22 17:21:42 e_di_CountDown_mybutton on
setstate di_CountDown 2024-08-22 17:21:42 error eval condition: Global symbol "$d" requires explicit package name (did you forget to declare "my $d"?) at (eval 343850) line 1.\
setstate di_CountDown 2024-08-22 17:21:34 mode enabled
setstate di_CountDown 2024-08-22 17:21:42 mybutton on
setstate di_CountDown 2024-08-22 17:21:34 state initialized
setstate di_CountDown 2024-08-22 17:21:39 test off
[/code]
$d muss sofort ausgewertet werden, $count erst später in set_Exec, daher:
set_Exec("countdown1",1,"set_Reading ('count1',$d-1-\$count,1)","\$count<$d");
-mit " werden Variablen ausgewertet, mit ' nicht
-bei " kann man mit \ die Auswertung einer Variablen unterbinden
Super cool: funktioniert
Vielen Dank