Tgo01
10-01-2016, 11:56 PM
I'm at a complete loss here. For my Dreavening events I have two different Hashes; one keeps track of how many times each person has attended a Dreavening, and the second variable keeps track of how many times they have attended a Dreavening for the current lottery I am holding.
The two Hashes started keeping track at different times so they should have different values for each person yet somehow the Hashes have become equal to one another and instead of adding 1 to each Hash value for every Dreavening the person attends it ends up adding 2 and the Hashes end up being equal to each other.
I stared at the code until my eyes bled (not literally) and could not figure out what the problem was. Finally I put a bunch of echos everywhere throughout the code to see exactly when the problem occurs and I have narrowed down where the problem happens but I still have no idea why this would be happening.
I feel like it's something simple I'm missing but I still don't see it.
The relevant code:
$pre_total_attendance = CharSettings['total_attendance'] unless $pre_total_attendance
$pre_total_lottery_attendance = CharSettings['current_lottery_attendance'] unless $pre_total_lottery_attendance
GameObj.pcs.each{|pc|
temp_attendance_value = nil
if $pre_total_attendance.include?(pc.noun)
temp_attendance_value = $pre_total_attendance.fetch(pc.noun)
CharSettings['total_attendance'].store(pc.noun, (temp_attendance_value + 1))
if $total_dreavenings
if CharSettings['total_attendance'].fetch(pc.noun) > $total_dreavenings
CharSettings['total_attendance'].store(pc.noun, $total_dreavenings)
end
end
else
CharSettings['total_attendance'].store(pc.noun, 1)
end
temp_attendance_value = nil
if $pre_total_lottery_attendance.include?(pc.noun)
##########PROBLEM HAPPENS BETWEEN HERE##########
temp_attendance_value = $pre_total_lottery_attendance.fetch(pc.noun)
CharSettings['current_lottery_attendance'].store(pc.noun, (temp_attendance_value + 1))
##########AND HERE##########
else
CharSettings['current_lottery_attendance'].store(pc.noun, 1)
end
}
So the values for everyone in CharSettings['total_attendance'] Hash go up by 1 like they should and they stay there until after the part I list in the code here then suddenly they go up by 1 again, yet I don't see how this is possible because two totally different Hashes are having their value increase by 1. Am I wrong here? Am I going crazy?
I've looked all over the code and I don't see anywhere where I have accidentally made the two Hashes equal to one another or anything of the sort, yet they are now equal to one another.
Is it because of the names of the Hashes somehow?
Strange thing is I've copied over this bit of code to a totally new script and kept all of the names the same and never saw this problem.
The two Hashes started keeping track at different times so they should have different values for each person yet somehow the Hashes have become equal to one another and instead of adding 1 to each Hash value for every Dreavening the person attends it ends up adding 2 and the Hashes end up being equal to each other.
I stared at the code until my eyes bled (not literally) and could not figure out what the problem was. Finally I put a bunch of echos everywhere throughout the code to see exactly when the problem occurs and I have narrowed down where the problem happens but I still have no idea why this would be happening.
I feel like it's something simple I'm missing but I still don't see it.
The relevant code:
$pre_total_attendance = CharSettings['total_attendance'] unless $pre_total_attendance
$pre_total_lottery_attendance = CharSettings['current_lottery_attendance'] unless $pre_total_lottery_attendance
GameObj.pcs.each{|pc|
temp_attendance_value = nil
if $pre_total_attendance.include?(pc.noun)
temp_attendance_value = $pre_total_attendance.fetch(pc.noun)
CharSettings['total_attendance'].store(pc.noun, (temp_attendance_value + 1))
if $total_dreavenings
if CharSettings['total_attendance'].fetch(pc.noun) > $total_dreavenings
CharSettings['total_attendance'].store(pc.noun, $total_dreavenings)
end
end
else
CharSettings['total_attendance'].store(pc.noun, 1)
end
temp_attendance_value = nil
if $pre_total_lottery_attendance.include?(pc.noun)
##########PROBLEM HAPPENS BETWEEN HERE##########
temp_attendance_value = $pre_total_lottery_attendance.fetch(pc.noun)
CharSettings['current_lottery_attendance'].store(pc.noun, (temp_attendance_value + 1))
##########AND HERE##########
else
CharSettings['current_lottery_attendance'].store(pc.noun, 1)
end
}
So the values for everyone in CharSettings['total_attendance'] Hash go up by 1 like they should and they stay there until after the part I list in the code here then suddenly they go up by 1 again, yet I don't see how this is possible because two totally different Hashes are having their value increase by 1. Am I wrong here? Am I going crazy?
I've looked all over the code and I don't see anywhere where I have accidentally made the two Hashes equal to one another or anything of the sort, yet they are now equal to one another.
Is it because of the names of the Hashes somehow?
Strange thing is I've copied over this bit of code to a totally new script and kept all of the names the same and never saw this problem.