List or resources or...?



  • I wanted to use lists because lists are limited to in-thread usage, while resources are in-script usage (all threads).

    I use this expression to get random line from a list:
    Math.floor(Math.random() * ([[_SPINTAX]].length - 0 + 1)) + 0

    alt text

    Problem is sometimes even if i set it to remove taken element from list, and then the list picks another element from same list (in loop of 20 iterations) then i get the same element! even thought he was supposed to be removed.

    Is there a specific time before the element gets removed from list? I assume its not instant. I have set waiters to 100miliseconds before it grabs another element from same list but it didnt do the job.

    What you use if you need to pick random unique line couple times?



  • @yourfriendkarol Makes sense from a thread/global standpoint, but how on Earth did you come to this zero stuffed formula? This should be it:

    Math.floor(Math.random() * [[_SPINTAX]].length)
    

    Your formula, set the useless zeros aside, often just hits beyond the upper array boundary effectively doing nothing. Hence nothing gets removed from the list, and LIST_ELEMENT1 keep holding the same value. This is the reason behind the artifacts you've been observing. See this happening in the first test case attached 0_1519097501637_tests03.xml.

    The second one is with the good formula, it works just as expected: 0_1519097551670_tests03_good.xml.



  • @daemons said in List or resources or...?:

    @yourfriendkarol Makes sense from a thread/global standpoint, but how on Earth did you come to this zero stuffed formula? This should be it:

    Math.floor(Math.random() * [[_SPINTAX]].length)
    

    Your formula, set the useless zeros aside, often just hits beyond the upper array boundary effectively doing nothing. Hence nothing gets removed from the list, and LIST_ELEMENT1 keep holding the same value. This is the reason behind the artifacts you've been observing. See this happening in the first test case attached 0_1519097501637_tests03.xml.

    The second one is with the good formula, it works just as expected: 0_1519097551670_tests03_good.xml.

    Oh I think your method solved the issue ! Thanks for it. I made many uneccessary script adjustments just to get rid of this issue but seems problem was with code.

    I got the expression from Visual Constructor. I picked "random number" and entered variable as max and 0 as minimum, since arrays start on index 0.



  • Seems it stil resulted in errors, so I downloaded your examples @daemons and I saw that you DEFINE expression as variable before getting element from list.

    Thats what did the problem. I entered expression instead of variable directly in list index. and there were duplicates each time i ran the script.

    I then looked at your script and the only difference was that you define expression in variable, I implemented it and it works fine now.

    I thought its fine to use expression in list index field, since it allows you to use "expression"



  • @yourfriendkarol Well, I'm a developer and not a single time I used the Visual Constructor for anything. I saw code snippets it generates, on the forum and in tutorial vids, and they look awful. Plus, for me it's faster to write everything I want myself.

    As for assigning the value to the variable, I only done that because I use this value multiple times. I'm not sure what happens in your own project, but just in case, keep in mind that each time you make a call to Math.random(), a new value is generated. That's the only reason for unexpected behavior that comes to my mind for now...



  • @daemons

    I couldnt replicate the error in your example but its in my project. I dont know whats causing it but when I've set "set variable" everywhere just before using list it started working like a charm.

    I need to learn javascript for basic operations, will help a lot in BAS



  • @yourfriendkarol said in List or resources or...?:

    I need to learn javascript for basic operations, will help a lot in BAS

    This path is not for the faint hearted, but it definitely pays out :)


Log in to reply
 

  • 3
  • 6
  • 3
  • 2
  • 4
  • 8
  • 6
  • 1