Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

[SugarCube] Updating arrays

$
0
0
Okay, I feel like I'm losing my mind. I've got a passage that is intended to take an array representing a group of people and split it into two arrays representing two groups of nearly-identical characteristics except the population is halved. The new arrays would then be saved into the master array of.

I copy the array into two new arrays ($original and $split) and then halve the population variables (in index 3). However, for reasons I cannot figure out, both halving operations are somehow applied to both arrays as well as the master array.

CODE:
We're splitting this population:

Prime:
<<print $units[$unit]>>
   
<<set $original = $units[$unit] ; $split = $units[$unit] ; $original[3] = Math.ceil($original[3]/2) ; $split[3] = Math.floor($split[3]/2) >>

Original:
<<print $original>>

New Pop:
<<print $split>>
 
UNIT:
<<print $units[$unit]>>

[[Dashboard]]

RESULT:
We're splitting this population:

Prime:
Hoafolk Clan, 34, 27, 28, 910, 0, 100, 20, 20, 71,44,91,63,62, 0,0,0, 0,0,14

Original:
Hoafolk Clan, 34, 27, 7, 910, 0, 100, 20, 20, 71,44,91,63,62, 0,0,0, 0,0,14

New Pop:
Hoafolk Clan, 34, 27, 7, 910, 0, 100, 20, 20, 71,44,91,63,62, 0,0,0, 0,0,14

UNIT:
Hoafolk Clan, 34, 27, 7, 910, 0, 100, 20, 20, 71,44,91,63,62, 0,0,0, 0,0,14

I'm sure I'm overlooking something stupid, but I cannot for the life of me find the problem!

Viewing all articles
Browse latest Browse all 1844

Trending Articles