Search Unity

Question for loop is not working properly, iterating twice as many times as it should

Discussion in 'Visual Scripting' started by White-studio, Dec 22, 2020.

  1. White-studio

    White-studio

    Joined:
    May 1, 2013
    Posts:
    7
    this is what i am creating, it is a clock if you will but a fully dynamic clock to be more precise, a clock where you can specify how many months there are in the year, how many days there are in each of the months you specified in the previous list, how many days there are in a week, everything else is fully automatic, you even get to decides how long in hours a day is, even how long an hour is in seconds, this gives you a lot of flexibility when creating your game.

    but there is a problem.

    one of the automatic systems works out how many weeks there are in the year, by iterating over the list where you specified how many days there are in each month and adding it to it self, then dividing it by how many days you specified there are in a week then rounding it up to the nearest whole number and saving it as an integer called Number of weeks.

    Another one of the automatic systems takes the int var Number of weeks, then iterates over it in a for loop and saves each number to a list called Weeks In Year, so say for instance there are 52 weeks in the year, the for loop should iterate over the number 52 times and save each number to the list so the list should have the numbers 1 all the way through to 52 in the list however the information is duplicated twice so the list goes 1 to 52 twice which is annoying so there are a 104 entries in the list not 52 like there should be, I'm totally confused.

    What the Weeks In Year list is used for is say for instance you want when the game starts for the calendar to start from the 6 march and you want to know which of the 52 weeks that is, and you also want to know how many days have already passed, these automatic systems work out all of that for you, they work out how many days have already passed, which week number you are on, what day you are on, what month yo are on, and so, but if the list has the same information in it repeated twice I'm not sure if i can really on that information, I should be able to work around it, but i would rather it only show the information i expect it to, i don't want any cyberpunk issues cropping up, since this clock and calendar system will be heavily influencing the weather system, day and night cycle and other systems in the game, if thee game thinks the date is something else when it should be something else entirely, the games behaviour is going to be catastrophic.

    here is a image of the list with the duplicated data.


    list pic 1.png List pic 2.png List pic 3.png List pic 4.png

    if any one can tell me why this is happening I would be much appreciated.

    Thank you

    Craig Richardson

    here is the image of my graph layout, screen is to small to fit the whole layout on the screen so I had to zoom out a bit, hope you you guys can tell what is going on.
    2020-12-22 (7).png
    if anyone on here has had a similar experience with the for loop before how did you get around it,
    thank you in advanced.
     
  2. White-studio

    White-studio

    Joined:
    May 1, 2013
    Posts:
    7
    Whoopsie, I had two different graphs writing to the same list, well it is nice to know my logic was working correctly I guess.

    just in case someone comes across this thread, I've learnt something from this and that is two always check your other graphs first before embarrassing myself online.