wrong list iteration

Just starting out? Need help? Post your questions and find answers here.
User avatar
William Van Hoecke
Posts: 50
Joined: Tue Oct 22, 2019 12:09 pm

wrong list iteration

Post by William Van Hoecke »

Hello,
I upgraded to 2.40 beta 1
The following code is behaving strangly different and incorrect on every browser-page-refresh (F5)
Am I doing something wrong here or could this be a bug ?

Code: Select all

Structure textstructure
  literal.s
  decoration.s
  enterflag.i
EndStructure

NewList list_one.textstructure()
NewList list_two.textstructure()

For i= 0 To 19                                                ;fill list_one with 20 elements
  txt.s + Chr(33+i)  
  AddElement(list_one())
  list_one()\literal = "(" + txt + ")"
Next
AddElement(list_two())                                        ;add 1 element to list_two
SelectElement(list_one(),Random(19,0))                        ;select a random element of list_one
SelectElement(list_two(),0)                                   ;select first element of list_two
AddElement(list_two())                                        ;add 1 element to list_two
SelectElement(list_one(),Random(19,0))                        ;select a random element of list_one
SelectElement(list_two(),1)                                   ;select first element of list_two

Debug "list_one listsize = " + Str(ListSize(list_one()))      ;show that list_one has 20 element 
Debug "list_two listsize = " + Str(ListSize(list_two()))      ;show that list_two has 2 element 
Debug "----------------------"

list_two() = list_one()                                       ;set current element of list_two = current element of list_one

ForEach list_two()                                            ;show all elements of list_two --> should be 2
  Debug List_two()\literal                                    ; but it is different on every F5 
Next list_two() 
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: wrong list iteration

Post by Peter »

use

Code: Select all

CopyList(list_one(), list_two())
instead of

Code: Select all

list_two() = list_one()
User avatar
William Van Hoecke
Posts: 50
Joined: Tue Oct 22, 2019 12:09 pm

Re: wrong list iteration

Post by William Van Hoecke »

Peter ...No can do....

during a loop trough list_one, I only need to copy certain elements form list_one to list_two...
Copylist however copies the entire list (according to documentation).

currently i copy every single value of the structure like this

Code: Select all

List_two()\literal = List_one()\literal
List_two()\decoration = List_one()\decoration
List_two()\enterflag = List_one()\enterflag
but I also have large structure and doing it like above works slow and increases code.
Post Reply