You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, October 2nd 2017, 6:12am

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

Monday, October 2nd 2017, 11:11am

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

This post has been edited 1 times, last edit by "indexofrefraction" (Oct 2nd 2017, 11:46am)


3

Monday, October 2nd 2017, 1:20pm

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

Monday, October 2nd 2017, 6:08pm

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

Monday, October 2nd 2017, 8:14pm

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 has attached the following image:
  • pr.jpg

6

Monday, October 2nd 2017, 9:23pm

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

Tuesday, October 3rd 2017, 2:39am

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

This post has been edited 1 times, last edit by "San7" (Oct 3rd 2017, 2:57am)


8

Tuesday, October 3rd 2017, 8:57am

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

Tuesday, October 3rd 2017, 10:08am

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*