[solved] using switch inside a loop?

  • Code
    switch(testit, 2, 1, 2, 1);
    	if(	get(testit),
    		trace('test it: ',get(testit));
    		switch(testit, 2, 1, 2, 1);
    		);

    is it possible to give a variable "testit" several values and than to work with these different values inside a loop.
    in my example, if all values of the variable are print on logwindow than exit/end the loop?
    (above code does not work)... or is the switch(variable, value1, value2, value3) etc.only usable for oncklick events and similar?

    many thanks in advance!
    Liebe Gruesse,
    Georg

    Edited once, last by gkaefer (January 17, 2012 at 1:25 PM).

  • I created followin action, but why do I get 9 x NULL instead of the values of the switch?

    Code
    <action name="testit">
    		showlog();
    		trace('--- action: ',%0,' ---');
    		set(var1,1); set(var2,9);
    		loop( 	var1 LE var2,
    			switch(testit,9,8,7,6,5,4,3,2,1);
    			trace('test it(',get(var1),'): ',get(testit) );
    			inc(var1);
    			);
    	</action>

    output:

    Code
    INFO: --- action: testit ---
    INFO: test it(1): null
    INFO: test it(2): null
    INFO: test it(3): null
    INFO: test it(4): null
    INFO: test it(5): null
    INFO: test it(6): null
    INFO: test it(7): null
    INFO: test it(8): null
    INFO: test it(9): null

    Liebe Gruesse,
    Georg

  • Hi,

    the switch action can only change existing variables!

    so just set/create the "testit" variable first,
    e.g.

    best regards,
    Klaus

  • thank you, Klaus - working now.

    is it possible to assign the switch values via external variable, like:

    <plugin...
    var2="1,2,3,4,5,67,8,9";
    ../plugin>

    <action...
    set(testit,1);
    switch(testit, get(plugin[..].var2));
    .../action>

    vorab besten Dank!
    Liebe Gruesse,
    Georg

  • so far all is clear, but it does not work on my side.
    it seems that after the switch the %1 cant be accessed anymore:

    the traceoutput shows me that %1 and %2 are correct loaded by myswitch
    but I cant access the %1 with its correct variable name after the switch, get(testit2) gives me null...
    I also tried to use '%2' inside the switch ... same result.

    many thanks in advance for your patience,
    Liebe Gruesse aus Salzburg,
    Georg

  • oh man,

    seems that "sitting on the line" is a my new hobby.
    it got it & found it & it works now.
    many thanks,
    Liebe Grüße,
    Georg

    the working code and the result:


    the result:

    Code
    INFO: --- action: myswitch ---
    INFO: myswitch (1):  5
    INFO: myswitch (2):  9
    INFO: myswitch (3):  12
    INFO: myswitch (4):  2
    INFO: myswitch (5):  1

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!