Last active
December 28, 2015 18:18
-
-
Save nickarthur/7541776 to your computer and use it in GitHub Desktop.
GLOBAL STATE SETTING AND GETTING EXAMPLE GIST FOR CLOUD PARTY CLOUDPARTY
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CLOUDPARTY GIST (smoosh together for searchability) | |
//////////////////////////// set global state examples //////////////////////////////////// | |
setGlobalState({ | |
state_key: 'Racetrack Key', | |
data: { controller: getSelfEnt() } //controller announce yo sef to da worl! | |
}); | |
setGlobalState({ | |
state_key: 'Racetrack Key', | |
data: { finishline: getSelfEnt() } //finish line you do the same! | |
}); | |
//put test data into the global state database for testing purposes | |
setGlobalState({ | |
state_key: 'Racetrack Key', | |
data: { | |
results_total: { | |
'1dbb9c6cd16ca166': { name: 'Garin Mazaika', time_finished: 1.010 }, //UserID is key | |
'19270e4bc1601c54': { name: 'Erin', time_finished: 1.140 }, | |
'54d7f469f60cf189': { name: 'Rubie', time_finished: 3.674 }, | |
'1f6e0dc783606745': { name: 'Beetle', time_finished: 5.962 }, | |
'596b6441f34db1b7': { name: 'Phate Shepherd', time_finished: 6.722 }, | |
'f3c82ea41cb195dc': { name: 'Jered Windsheimer', time_finished: 16.345 }, | |
'e2e7d3979ae76a31': { name: 'Miser', time_finished: 21.248 }, | |
'fb5d615d9aa615c9': { name: 'Cyn Skyberg', time_finished: 21.248 }, | |
'6e54f6c00219de76': { name: 'NickArthur Night', time_finished: 23.420 }, | |
'077a50076474afb2': { name: 'Mochi', time_finished: 30.553 }, | |
'e62d3de1261854a7': { name: 'Lilli Thompson', time_finished: 38.983 }, | |
'b54f303854b4c8c9': { name: 'Jimb Esser', time_finished: 42.097 }, | |
'e0a416afeb70ace8': { name: 'The Illusionist', time_finished: 60.511 }, | |
'5906c2bdd2d42828': { name: 'Sam Thompson', time_finished: 72.231 }, | |
'b2d9a74e14814388': { name: 'Conor', time_finished: 80.221 } | |
}, | |
results_current: {} | |
}, | |
callback: 'addedResults' | |
}); | |
//////////////////////////// clear global state examples //////////////////////////////////// | |
// clear global state variables on click by setting to empty objects | |
function clickStart() { | |
setGlobalState({ | |
state_key: 'Racetrack Key', | |
data: { | |
results_total: {}, | |
results_current: {} | |
}, | |
callback: 'clearedResults' | |
}); | |
} | |
//////////////////////////// get and use global state example //////////////////////////////////// | |
getGlobalState({ | |
state_key: 'Racetrack Key', | |
keys: ['results_total'], | |
callback: 'processResults', | |
callback_data: { current_racers: racersProcessed } | |
}); | |
function processResults(globalStateData){ | |
//do some stuff | |
for (var current_racer in globalStateData.current_racers) { | |
for (var total_racer in globalStateData.results_total) | |
... | |
} | |
//////////////////////////// clear global state example //////////////////////////////////// | |
setGlobalState({ | |
state_key: 'Racetrack Key', | |
data: { | |
results_total: {}, | |
results_current: {} | |
}, | |
callback: 'clearedResults' | |
}); | |
//////////////////////////// //////////////////////////////////// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment