MySQL_Narb Posted January 12, 2014 Share Posted January 12, 2014 Here is bossScenario: var bossScenario = { 'active': false, 'scenario_ID':0, 'boss': {} }; Here is a list of scenarios: var scenarios = { 1 : { 'func' : function(bossDifficulty){ /*var me = bossScenario['boss'][1]; var vars = me['vars']; vars[rbSoldiers] = bossDifficulty*100000; vars[reward] = bossDifficulty;*/ alert('test'); //randBossBattle(vars); }, 'vars' : { rbSoldiers : 0, reward : 0 } } } In bossScenario, I will assign a scenario to the 'boss' property. And then I will run the below code: bossScenario['boss'][sID]['func'](bossDifficulty); The above code will successfully alert "test"; however, next time I go to run the function, I get this error in the console: Uncaught TypeError: Object #<Object> has no method 'func' It's as if the 'func' property and its function are being removed from the bossScenario function after it is ran. Why is this? Link to comment https://forums.phpfreaks.com/topic/285297-function-in-object-keeps-disappearing-after-being-executed/ Share on other sites More sharing options...
MySQL_Narb Posted January 12, 2014 Author Share Posted January 12, 2014 This has been solved. JSON does not parse functions! Link to comment https://forums.phpfreaks.com/topic/285297-function-in-object-keeps-disappearing-after-being-executed/#findComment-1464897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.