Hi guys!
I’m working on a water-play-tile (outside) whicn means: a tile with 5 holes in it with water coming out. Now i’'ve built all logic in PHP. But now i’m trying to translate it to Ninja or whatever is needed.
But i dunno where to start. Is it even possible what i want? Or is another way easier?
Own writtten PHP code:
<?php
$pins = ['water_pin_14', 'water_pin_16', 'water_pin_17', 'water_pin_18', 'water_pin_19'];
$scriptStarted = true;
$maxIterations = 30;
$counter = 0;
$randomAmounts = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,5,5];
while($scriptStarted and $counter < $maxIterations) {
// Shuffle array
shuffle($pins);
// Shuffle randomAmounts
shuffle($randomAmounts);
// Pick random keys
$randomPinKeys = array_rand($pins, $randomAmounts[0]);
// If $randomPinKeys contains one element, it's unfortunately casted to int, cast it back to array
if (is_numeric($randomPinKeys)) {
$randomPinKeys = [0 => $randomPinKeys];
}
// Turn off all pins
foreach($pins as $pin) {
echo 'turn off pin ' . $pin . PHP_EOL;
}
// Turn on random picked pins
foreach ($randomPinKeys as $randomPinKey) {
echo 'turning on pin ' . $pins[$randomPinKey] . PHP_EOL;
}
sleep(rand(3,8)); // Random wait between 3 and 8 seconds
$counter++;
}
Edit
Fixed, please check below!