Sie sind nicht angemeldet.

1

Montag, 2. Oktober 2017, 06:12

txtsplit How right?

Hello! I'm trying to use thtsplit
and here's what happens:

INFO: krpano 1.19-pr12 (build 2017-08-04)

<action name="proba">
txtsplit('a,b',',',arr);
for(set(i,0), i LT arr.count, inc(i),
set(PR,arr[get(i)].value);
trace(PR=,get(PR));
txtadd(PR2,get(PR));
trace(PR2=,get(PR2));
);
</action>

outputs:

INFO: PR=a
INFO: PR2=a
INFO: PR=b
INFO: PR2=arr[get(i)].valuearr[get(i)].value

Should not it be so?
INFO: PR2=ab

And another example:

<action name="proba2">
txtsplit('a,b|c,d','|',arr);
for(set(i,0), i LT arr.count, inc(i),
set(PR,arr[get(i)].value);
trace(PR=,get(PR));
proc(get(PR));
);
</action>

<action name="proc">
trace(proc=,%1,%2);
</action>

outputs:

INFO: PR=a,b
INFO: proc=a,bnull
INFO: PR=c,d
INFO: proc=c,dnull

Should not it be so?

INFO: PR=a,b
INFO: proc=ab
INFO: PR=c,d
INFO: proc=cd

?

2

Montag, 2. Oktober 2017, 11:11

copy(PR,arr[get(i)].value);
trace(PR=,PR); <!-- no get here! -->

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »indexofrefraction« (2. Oktober 2017, 11:46)


3

Montag, 2. Oktober 2017, 13:20

copy(PR,arr[get(i)].value);
trace(PR=,PR); <!-- no get here! -->



Thank you! The first example works!
The second is not

<action name="proba2">
txtsplit('a,b|c,d','|',arr);
for(set(i,0), i LT arr.count, inc(i),
copy(PR,arr[get(i)].value);
proc(PR); <!-- proc(a,b) ? -->
);
</action>
<action name="proc">
trace(proc=,%1,%2); <!-- proc=ab ? -->
</action>

It turns out
%1=a,b %2=null ?

4

Montag, 2. Oktober 2017, 18:08

in GENERAL :
trace(), debug(), error(), calc() do not need get(), pretty much everything else does.

if you do :
set(PR,arr[get(i)].value); --> PR = "arr[get(i)].value"
trace(get(PR)); --> "arr[get(i)].value" --> "a" or depending on the last i, which can be wrong

copy(PR,arr[get(i)].value); --> PR = "a"
trace(PR); --> "a"

you could also do
set(PR,get(arr[get(i)].value)); --> but this is the same as copy

so :
proc(get(PR)); --> means proc("a") --> then you can do trace(%1) in proc() --> this is what you want
proc(PR) --> means proc("PR"); ---> then you have to do trace(get(%1)); in proc() --> possible but not good

test things out ;)


your 2nd example is strange... why do you expect %2 if you do only proc(pr) ??
proc("a") -> %1 = "a"
proc("a","b") -> %1 = "a", %2 = "b"
etc..

proc(get(arr[0].value), get(arr[1].value)); --> this will give you %1="a,b" %2="c,d"

5

Montag, 2. Oktober 2017, 20:14

your 2nd example is strange... why do you expect %2 if you do only proc(pr) ??
proc("a") -> %1 = "a"
proc("a","b") -> %1 = "a", %2 = "b"
etc..

proc(get(arr[0].value), get(arr[1].value)); --> this will give you %1="a,b" %2="c,d"
The second example is the separator "|"
We obtain for pr = a, b and pr = c, d
This means proc (get (pr)); -> proc (a, b); and proc (c,d);


<action name="proc">
trace(proc=,%1,%2);
</action>



should receive - INFO: PR=ab and INFO: PR=cd

but we get - INFO: PR=a,bnull and INFO: PR=c,dnull
»San7« hat folgendes Bild angehängt:
  • pr.jpg

6

Montag, 2. Oktober 2017, 21:23

ahh.. okk... well you have ideas ;P

if you pass "a,b" to an action with proc("a,b");
you cant trace(%1, %2) because %1 = "a,b"

if you do proc("a","b");
now you can do trace(%1, %2) because %1 = "a", %2 ="b"

note: "a,b" is one string, "a","b" are two strings!

7

Dienstag, 3. Oktober 2017, 02:39

Thanks, I thought so, but at first glance looks the same without the quotes

("a,b"); and ("a","b");

<action name="proba3">
txtsplit('a,b',',',arr);
for(set(i,0), i LT arr.count, inc(i),
copy(PR1,arr[0].value);
copy(PR2,arr[1].value);
);
proc(get(PR1),get(PR2));
</action>


<action name="proc">
trace(proc=,%1,%2);
</action>

now we get proc=ab

Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »San7« (3. Oktober 2017, 02:57)


8

Dienstag, 3. Oktober 2017, 08:57

the for/next loop is useless here, you dont need it !
<action name="proba3">
txtsplit('a,b',',',arr);
copy(PR1,arr[0].value);
copy(PR2,arr[1].value);
proc(get(PR1),get(PR2));
</action>

or...
[/b]<action name="proba3">
txtsplit('a,b',',',arr);
proc(get(arr[0].value1),get(arr[1].value));
</action>

<action name="proc">
trace(proc=,%1,%2);
</action>

but.. you could also do this...
<action name="proba3">
delete(arr); <!-- only needed if arr was already used before (is not empty) -->
txtsplit('a,b,c,d,e',',',arr);
proc(arr);
</action>

<action name="proc">
set(pr,'');
for(set(i,0), i LT %1.count, inc(i),
txtadd(pr,get(pr),get(%1[get(i)].value));
);
trace(pr);
</action>

welcome to krpano
happy coding ;)

9

Dienstag, 3. Oktober 2017, 10:08

or...

txtsplit('a,b',',',arr);
proc(get(arr[0].value1),get(arr[1].value));
</action>

trace(proc=,%1,%2);
</action>
but.. you could also do this...

delete(arr);
txtsplit('a,b,c,d,e',',',arr);
proc(arr);
</action>

set(pr,'');
for(set(i,0), i LT %1.count, inc(i),
txtadd(pr,get(pr),get(%1[get(i)].value));
);
trace(pr);
</action>
welcome to krpano
great! Thank you for your helpful examples! *thumbsup* *thumbsup* *thumbsup*