ScriptManager.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. #include "core/ConfigVar.h"
  2. #include "core/DebugDraw.h"
  3. #include "core/Logger.h"
  4. #include "core/ScriptManager.h"
  5. #include "core/ScriptManagerBinds.h"
  6. #include "core/ScriptManagerCommands.h"
  7. #include "core/Timer.h"
  8. #include "core/Utilites.h"
  9. #include "core/XmlScriptsFile.h"
  10. #include "LuaIncludes.h"
  11. ConfigVar cv_debug_script("debug_script", "Debug script flags. 0x01 - System, 0x02 - Entity, 0x04 - Ui.", "0");
  12. template<>ScriptManager *Ogre::Singleton<ScriptManager>::msSingleton = nullptr;
  13. Ogre::String script_entity_type[] = {"SYSTEM", "ENTITY", "UI"};
  14. bool
  15. priority_queue_compare(QueueScript a, QueueScript b)
  16. {
  17. return a.priority < b.priority;
  18. }
  19. ScriptManager::ScriptManager():
  20. m_SystemTableName("System"),
  21. m_EntityTableName("EntityContainer"),
  22. m_UiTableName("UiContainer")
  23. {
  24. LOG_TRIVIAL("ScriptManager started.");
  25. m_LuaState = lua_open();
  26. luabind::open(m_LuaState);
  27. luaopen_base(m_LuaState);
  28. luaopen_string(m_LuaState);
  29. luaopen_table(m_LuaState);
  30. luaopen_math(m_LuaState);
  31. InitBinds();
  32. InitCmd();
  33. RunFile("system/system.lua");
  34. XmlScriptsFile scripts("./data/scripts.xml");
  35. scripts.LoadScripts();
  36. }
  37. ScriptManager::~ScriptManager()
  38. {
  39. lua_close(m_LuaState);
  40. LOG_TRIVIAL("ScriptManager closed.");
  41. }
  42. void
  43. ScriptManager::Input(const QGears::Event& event)
  44. {
  45. if ((event.type == QGears::ET_KEY_PRESS || event.type == QGears::ET_KEY_REPEAT_WAIT) &&
  46. (
  47. event.param1 == OIS::KC_RETURN ||
  48. event.param1 == OIS::KC_ESCAPE ||
  49. event.param1 == OIS::KC_SPACE ||
  50. event.param1 == OIS::KC_LCONTROL ||
  51. event.param1 == OIS::KC_LEFT ||
  52. event.param1 == OIS::KC_RIGHT ||
  53. event.param1 == OIS::KC_DOWN ||
  54. event.param1 == OIS::KC_UP
  55. ))
  56. {
  57. for(unsigned int i = 0; i < m_ScriptEntity.size(); ++i)
  58. {
  59. Ogre::String argument2 = "";
  60. if (event.type == QGears::ET_KEY_PRESS)
  61. {
  62. argument2 = "Press";
  63. }
  64. else if (event.type == QGears::ET_KEY_REPEAT_WAIT)
  65. {
  66. argument2 = "Repeat";
  67. }
  68. ScriptRequest(&m_ScriptEntity[i], "on_button", 100, KeyToString((OIS::KeyCode)((int)event.param1)), argument2, false, false);
  69. }
  70. }
  71. }
  72. void
  73. ScriptManager::Update(const ScriptManager::Type type)
  74. {
  75. // resort all queue. This will give us correct info for debug draw.
  76. for(unsigned int i = 0; i < m_ScriptEntity.size(); ++i)
  77. {
  78. if(m_ScriptEntity[i].type == type)
  79. {
  80. if(m_ScriptEntity[i].queue.size() > 0)
  81. {
  82. if(m_ScriptEntity[i].resort == true)
  83. {
  84. std::stable_sort(m_ScriptEntity[i].queue.begin(), m_ScriptEntity[i].queue.end(), priority_queue_compare);
  85. m_ScriptEntity[i].resort = false;
  86. }
  87. }
  88. }
  89. }
  90. // draw debug before update. This way it will be posible to see scripts that run once
  91. int debug = cv_debug_script.GetI();
  92. if(debug != 0)
  93. {
  94. DEBUG_DRAW.SetTextAlignment(DEBUG_DRAW.LEFT);
  95. DEBUG_DRAW.SetScreenSpace(true);
  96. int y = 34;
  97. for(unsigned int i = 0; i < 3; ++i)
  98. {
  99. if((debug & (1 << i)) != 0)
  100. {
  101. DEBUG_DRAW.SetColour(Ogre::ColourValue(0.8f, 0.8f, 0.0f, 1.0f));
  102. DEBUG_DRAW.Text(10.0f, static_cast<float>(y), "Script \"" + script_entity_type[i] + "\" entity:");
  103. y += 16;
  104. for(unsigned int j = 0; j < m_ScriptEntity.size(); ++j)
  105. {
  106. if(m_ScriptEntity[j].type == i)
  107. {
  108. Ogre::String text = m_ScriptEntity[j].name;
  109. unsigned int queue_size = m_ScriptEntity[j].queue.size();
  110. if(queue_size > 0)
  111. {
  112. text += ": ";
  113. DEBUG_DRAW.SetColour(Ogre::ColourValue(0.8f, 0.8f, 0.0f, 1.0f));
  114. }
  115. else
  116. {
  117. DEBUG_DRAW.SetColour(Ogre::ColourValue(0.5, 0.5, 0.5, 1));
  118. }
  119. for(unsigned int k = 0; k < queue_size; ++k)
  120. {
  121. if(k > 0)
  122. {
  123. text += ", ";
  124. }
  125. text += "(" + Ogre::StringConverter::toString(m_ScriptEntity[j].queue[k].priority) + ")" + m_ScriptEntity[j].queue[k].function;
  126. if(m_ScriptEntity[j].queue[k].wait == true)
  127. {
  128. if(m_ScriptEntity[j].queue[k].seconds_to_wait != 0)
  129. {
  130. text += ":wait(" + Ogre::StringConverter::toString(m_ScriptEntity[j].queue[k].seconds_to_wait) + ")";
  131. }
  132. }
  133. }
  134. DEBUG_DRAW.Text(20.0f, static_cast<float>(y), text);
  135. y += 16;
  136. }
  137. }
  138. }
  139. }
  140. }
  141. for(unsigned int i = 0; i < m_ScriptEntity.size(); ++i)
  142. {
  143. if(m_ScriptEntity[i].type == type)
  144. {
  145. if(m_ScriptEntity[i].queue.size() > 0)
  146. {
  147. m_CurrentScriptId.entity = m_ScriptEntity[i].name;
  148. m_CurrentScriptId.function = m_ScriptEntity[i].queue[0].function;
  149. if(m_ScriptEntity[i].queue[0].wait == false)
  150. {
  151. if(m_ScriptEntity[i].queue[0].yield == false)
  152. {
  153. LOG_TRIVIAL("[SCRIPT] Start script \"" + m_CurrentScriptId.function + "\" for entity \"" + m_CurrentScriptId.entity + "\".");
  154. if(m_ScriptEntity[i].queue[0].paused_script_start.entity != "")
  155. {
  156. ContinueScriptExecution(m_ScriptEntity[i].queue[0].paused_script_start);
  157. m_ScriptEntity[i].queue[0].paused_script_start.entity = "";
  158. }
  159. luabind::object table = GetTableByEntityName(type, m_CurrentScriptId.entity, m_ScriptEntity[i].queue[0].state);
  160. if(table.is_valid() &&
  161. luabind::type(table) == LUA_TTABLE &&
  162. luabind::type(table[m_CurrentScriptId.function]) == LUA_TFUNCTION)
  163. {
  164. int ret = 0;
  165. try
  166. {
  167. ret = luabind::resume_function< int >(table[m_CurrentScriptId.function], table, m_ScriptEntity[i].queue[0].argument1.c_str(), m_ScriptEntity[i].queue[0].argument2.c_str());
  168. }
  169. catch(luabind::error& /*e*/)
  170. {
  171. LOG_ERROR(Ogre::String(lua_tostring(m_ScriptEntity[i].queue[0].state , -1)));
  172. }
  173. if(ret == 0)
  174. {
  175. LOG_TRIVIAL("[SCRIPT] Script \"" + m_CurrentScriptId.function + "\" for entity \"" + m_CurrentScriptId.entity + "\" finished.");
  176. if(m_ScriptEntity[i].queue[0].function != "on_update")
  177. {
  178. RemoveEntityTopScript(m_ScriptEntity[i]);
  179. }
  180. }
  181. else if(ret == 1)
  182. {
  183. LOG_TRIVIAL("[SCRIPT] Script \"" + m_CurrentScriptId.function + "\" for entity \"" + m_CurrentScriptId.entity + "\" not paused and will be continued next cycle.");
  184. m_ScriptEntity[i].queue[0].yield = true;
  185. }
  186. else
  187. {
  188. LOG_TRIVIAL("[SCRIPT] Script \"" + m_CurrentScriptId.function + "\" for entity \"" + m_CurrentScriptId.entity + "\" not finished yet.");
  189. m_ScriptEntity[i].queue[0].yield = true;
  190. m_ScriptEntity[i].queue[0].wait = true;
  191. }
  192. }
  193. else
  194. {
  195. LOG_WARNING("Script \"" + m_CurrentScriptId.function + "\" for entity \"" + m_CurrentScriptId.entity + "\" doesn't exist.");
  196. RemoveEntityTopScript(m_ScriptEntity[i]);
  197. }
  198. }
  199. else
  200. {
  201. LOG_TRIVIAL("[SCRIPT] Continue function \"" + m_CurrentScriptId.function + "\" for entity \"" + m_CurrentScriptId.entity + "\".");
  202. int ret = 0;
  203. try
  204. {
  205. ret = luabind::resume< int >(m_ScriptEntity[i].queue[0].state);
  206. }
  207. catch(luabind::error& e)
  208. {
  209. luabind::object error_msg(luabind::from_stack(e.state(), -1));
  210. LOG_WARNING(Ogre::String(luabind::object_cast< std::string >(error_msg)));
  211. }
  212. if(ret == 0) // finished
  213. {
  214. LOG_TRIVIAL("[SCRIPT] Script \"" + m_CurrentScriptId.function + "\" for entity \"" + m_CurrentScriptId.entity + "\" finished.");
  215. // stop yield for on_update
  216. m_ScriptEntity[i].queue[0].yield = false;
  217. if(m_ScriptEntity[i].queue[0].function != "on_update")
  218. {
  219. RemoveEntityTopScript(m_ScriptEntity[i]);
  220. }
  221. }
  222. else if(ret == 1)
  223. {
  224. LOG_TRIVIAL("[SCRIPT] Script \"" + m_CurrentScriptId.function + "\" for entity \"" + m_CurrentScriptId.entity + "\" not paused and will be continued next cycle.");
  225. }
  226. else
  227. {
  228. LOG_TRIVIAL("[SCRIPT] Script \"" + m_CurrentScriptId.function + "\" for entity \"" + m_CurrentScriptId.entity + "\" not finished yet.");
  229. m_ScriptEntity[i].queue[0].wait = true;
  230. }
  231. }
  232. }
  233. else if(m_ScriptEntity[i].queue[0].seconds_to_wait > 0)
  234. {
  235. m_ScriptEntity[i].queue[0].seconds_to_wait -= Timer::getSingleton().GetGameTimeDelta();
  236. m_ScriptEntity[i].queue[0].seconds_to_wait = (m_ScriptEntity[i].queue[0].seconds_to_wait < 0) ? 0 : m_ScriptEntity[i].queue[0].seconds_to_wait;
  237. if(m_ScriptEntity[i].queue[0].seconds_to_wait == 0)
  238. {
  239. m_ScriptEntity[i].queue[0].wait = false;
  240. }
  241. }
  242. }
  243. }
  244. }
  245. }
  246. void
  247. ScriptManager::RunString(const Ogre::String& lua)
  248. {
  249. int preEvalIndex = lua_gettop(m_LuaState);
  250. if(luaL_dostring(m_LuaState, lua.c_str()) == 1)
  251. {
  252. LOG_ERROR(Ogre::String(lua_tostring(m_LuaState, -1)));
  253. }
  254. else
  255. {
  256. int index = lua_gettop(m_LuaState);
  257. if (index > 0 && index != preEvalIndex)
  258. {
  259. auto str = lua_tostring(m_LuaState, index);
  260. LOG_CONSOLE(str != nullptr ? str : "(nullptr; try tostring(...)?)");
  261. lua_pop(m_LuaState, 1);
  262. }
  263. }
  264. }
  265. void
  266. ScriptManager::RunFile(const Ogre::String& file)
  267. {
  268. if(luaL_dofile(m_LuaState, ("./data/" + file).c_str()) == 1)
  269. {
  270. LOG_ERROR(Ogre::String(lua_tostring(m_LuaState, -1)));
  271. }
  272. }
  273. void
  274. ScriptManager::AddEntity(const ScriptManager::Type type, const Ogre::String& entity_name, Entity* entity)
  275. {
  276. for(unsigned int i = 0; i < m_ScriptEntity.size(); ++i)
  277. {
  278. if(m_ScriptEntity[i].type == type && m_ScriptEntity[i].name == entity_name)
  279. {
  280. LOG_ERROR("Script \"" + script_entity_type[type] + "\" entity \"" + entity_name + "\" already exist in script manager.");
  281. return;
  282. }
  283. }
  284. luabind::object table = GetTableByEntityName(type, entity_name, m_LuaState);
  285. if(table.is_valid() && luabind::type(table) == LUA_TTABLE)
  286. {
  287. ScriptEntity script_entity;
  288. script_entity.name = entity_name;
  289. script_entity.type = type;
  290. // init entity field for model entity
  291. if(entity != nullptr)
  292. {
  293. table["entity"] = boost::ref(*entity);
  294. }
  295. // check "on_start" script
  296. if(luabind::type(table["on_start"]) == LUA_TFUNCTION)
  297. {
  298. QueueScript script;
  299. script.function = "on_start";
  300. script.priority = 1;
  301. script.state = lua_newthread(m_LuaState);
  302. // we dont want thread to be garbage collected so we store it
  303. script.state_id = luaL_ref(m_LuaState, LUA_REGISTRYINDEX);
  304. script.seconds_to_wait = 0;
  305. script.wait = false;
  306. script.yield = false;
  307. script_entity.queue.push_back(script);
  308. }
  309. // check "on_update" script
  310. if(luabind::type(table["on_update"]) == LUA_TFUNCTION)
  311. {
  312. QueueScript script;
  313. script.function = "on_update";
  314. script.priority = 999;
  315. script.state = lua_newthread(m_LuaState);
  316. // we dont want thread to be garbage collected so we store it
  317. script.state_id = luaL_ref(m_LuaState, LUA_REGISTRYINDEX);
  318. script.seconds_to_wait = 0;
  319. script.wait = false;
  320. script.yield = false;
  321. script_entity.queue.push_back(script);
  322. }
  323. m_ScriptEntity.push_back(script_entity);
  324. }
  325. }
  326. void
  327. ScriptManager::RemoveEntity(const ScriptManager::Type type, const Ogre::String& entity_name)
  328. {
  329. for(unsigned int i = 0; i < m_ScriptEntity.size(); ++i)
  330. {
  331. if(m_ScriptEntity[i].type == type && m_ScriptEntity[i].name == entity_name)
  332. {
  333. while(m_ScriptEntity[i].queue.size() > 0)
  334. {
  335. ScriptManager::RemoveEntityTopScript(m_ScriptEntity[i]);
  336. }
  337. m_ScriptEntity.erase(m_ScriptEntity.begin() + i);
  338. return;
  339. }
  340. }
  341. }
  342. void
  343. ScriptManager::RemoveEntityTopScript(ScriptEntity& entity)
  344. {
  345. if(entity.queue.size() > 0)
  346. {
  347. // delete thread
  348. luaL_unref(m_LuaState, LUA_REGISTRYINDEX, entity.queue[0].state_id);
  349. if(entity.queue[0].paused_script_end.entity != "")
  350. {
  351. ContinueScriptExecution(entity.queue[0].paused_script_end);
  352. entity.queue[0].paused_script_end.entity = "";
  353. }
  354. entity.queue.erase(entity.queue.begin());
  355. }
  356. }
  357. luabind::object
  358. ScriptManager::GetTableByEntityName(const ScriptManager::Type type, const Ogre::String& name, lua_State* state) const
  359. {
  360. // get real table by name
  361. Ogre::StringVector table_path = StringTokenise(name, ".");
  362. luabind::object table = luabind::globals(state);
  363. switch(type)
  364. {
  365. case ScriptManager::SYSTEM: table = table[m_SystemTableName]; break;
  366. case ScriptManager::ENTITY: table = table[m_EntityTableName]; break;
  367. case ScriptManager::UI: table = table[m_UiTableName]; break;
  368. }
  369. if(luabind::type(table) != LUA_TTABLE)
  370. {
  371. return luabind::object();
  372. }
  373. for(unsigned int i = 0; i < table_path.size(); ++i)
  374. {
  375. table = table[table_path[i]];
  376. if(luabind::type(table) != LUA_TTABLE)
  377. {
  378. return luabind::object();
  379. }
  380. }
  381. return table;
  382. }
  383. QueueScript*
  384. ScriptManager::GetScriptByScriptId(const ScriptId& script) const
  385. {
  386. for(unsigned int i = 0; i < m_ScriptEntity.size(); ++i)
  387. {
  388. if(script.entity == m_ScriptEntity[i].name)
  389. {
  390. for(unsigned int j = 0; j < m_ScriptEntity[i].queue.size(); ++j)
  391. {
  392. if(script.function == m_ScriptEntity[i].queue[j].function)
  393. {
  394. return (QueueScript*) &(m_ScriptEntity[i].queue[j]);
  395. }
  396. }
  397. return nullptr;
  398. }
  399. }
  400. return nullptr;
  401. }
  402. ScriptEntity*
  403. ScriptManager::GetScriptEntityByName(const Type type, const Ogre::String& entity_name) const
  404. {
  405. for(unsigned int i = 0; i < m_ScriptEntity.size(); ++i)
  406. {
  407. if(m_ScriptEntity[i].type == type && m_ScriptEntity[i].name == entity_name)
  408. {
  409. return (ScriptEntity*) &(m_ScriptEntity[i]);
  410. }
  411. }
  412. return nullptr;
  413. }
  414. const ScriptId
  415. ScriptManager::GetCurrentScriptId() const
  416. {
  417. return m_CurrentScriptId;
  418. }
  419. void
  420. ScriptManager::ContinueScriptExecution(const ScriptId& script)
  421. {
  422. QueueScript* script_pointer = GetScriptByScriptId(script);
  423. if(script_pointer == nullptr)
  424. {
  425. LOG_ERROR("There is no script \"" + script.function + "\" for entity \"" + script.entity + "\". Can't continue script execution.");
  426. return;
  427. }
  428. script_pointer->wait = false;
  429. }
  430. int
  431. ScriptManager::ScriptWait(const float seconds)
  432. {
  433. LOG_TRIVIAL("script:wait: We set script wait for " + Ogre::StringConverter::toString(seconds) + " seconds.");
  434. QueueScript* script = GetScriptByScriptId(m_CurrentScriptId);
  435. if(script == nullptr)
  436. {
  437. LOG_ERROR("script:wait: Currently no any script running.");
  438. return 1;
  439. }
  440. if(seconds == 0)
  441. {
  442. return 1;
  443. }
  444. script->seconds_to_wait = seconds;
  445. return -1;
  446. }
  447. void
  448. ScriptManager::ScriptRequest(const Type type, const char* entity, const char* function, const int priority)
  449. {
  450. LOG_TRIVIAL("[SCRIPT] script:request: Request function \"" + Ogre::String(function) + "\" for entity \"" + Ogre::String(entity) + "\" with priority " + Ogre::StringConverter::toString(priority) + ".");
  451. ScriptEntity* script_entity = GetScriptEntityByName(type, Ogre::String(entity));
  452. if(script_entity == nullptr)
  453. {
  454. LOG_WARNING("[SCRIPT] script:request: Entity \"" + Ogre::String(entity) + "\" doesn't exist.");
  455. return;
  456. }
  457. bool added = ScriptRequest(script_entity, function, priority, "", "", false, false);
  458. if(added == false)
  459. {
  460. LOG_WARNING("Script '" + Ogre::String(function) + "' for entity '" + Ogre::String(entity) + "' doesn't exist.");
  461. }
  462. }
  463. int
  464. ScriptManager::ScriptRequestStartSync(const Type type, const char* entity, const char* function, const int priority)
  465. {
  466. LOG_TRIVIAL("[SCRIPT] script:request_start_sync: Request function \"" + Ogre::String(function) + "\" for entity \"" + Ogre::String(entity) + "\" with priority " + Ogre::StringConverter::toString(priority) + ".");
  467. ScriptEntity* script_entity = GetScriptEntityByName(type, Ogre::String(entity));
  468. if(script_entity == nullptr)
  469. {
  470. LOG_ERROR("[SCRIPT] script:request_start_sync: Entity \"" + Ogre::String(entity) + "\" doesn't exist.");
  471. return 1;
  472. }
  473. bool added = ScriptRequest(script_entity, function, priority, "", "", true, false);
  474. if(added == false)
  475. {
  476. LOG_WARNING("Script '" + Ogre::String(function) + "' for entity '" + Ogre::String(entity) + "' doesn't exist.");
  477. return 1;
  478. }
  479. return -1;
  480. }
  481. int
  482. ScriptManager::ScriptRequestEndSync(const Type type, const char* entity, const char* function, const int priority)
  483. {
  484. LOG_TRIVIAL("[SCRIPT] script:request_end_sync: Request function \"" + Ogre::String(function) + "\" for entity \"" + Ogre::String(entity) + "\" with priority " + Ogre::StringConverter::toString(priority) + ".");
  485. ScriptEntity* script_entity = GetScriptEntityByName(type, Ogre::String(entity));
  486. if(script_entity == nullptr)
  487. {
  488. LOG_ERROR("[SCRIPT] script:request_end_sync: Entity \"" + Ogre::String(entity) + "\" doesn't exist.");
  489. return 1;
  490. }
  491. bool added = ScriptRequest(script_entity, function, priority, "", "", false, true);
  492. if(added == false)
  493. {
  494. LOG_WARNING("Script '" + Ogre::String(function) + "' for entity '" + Ogre::String(entity) + "' doesn't exist.");
  495. return 1;
  496. }
  497. return -1;
  498. }
  499. bool
  500. ScriptManager::ScriptRequest(ScriptEntity* script_entity, const Ogre::String& function, const int priority, const Ogre::String& argument1, const Ogre::String& argument2, bool start_sync, bool end_sync)
  501. {
  502. luabind::object table = GetTableByEntityName(script_entity->type, script_entity->name, m_LuaState);
  503. if(table.is_valid() && luabind::type(table) == LUA_TTABLE && luabind::type(table[function]) == LUA_TFUNCTION)
  504. {
  505. QueueScript script;
  506. script.function = function;
  507. script.argument1 = argument1;
  508. script.argument2 = argument2;
  509. script.priority = priority;
  510. script.state = lua_newthread(m_LuaState);
  511. // we dont want thread to be garbage collected so we store it
  512. script.state_id = luaL_ref(m_LuaState, LUA_REGISTRYINDEX);
  513. script.seconds_to_wait = 0;
  514. script.wait = false;
  515. script.yield = false;
  516. if(start_sync == true)
  517. {
  518. script.paused_script_start = GetCurrentScriptId();
  519. }
  520. if(end_sync == true)
  521. {
  522. script.paused_script_end = GetCurrentScriptId();
  523. }
  524. script_entity->queue.push_back(script);
  525. script_entity->resort = true;
  526. return true;
  527. }
  528. return false;
  529. }
  530. void
  531. ScriptManager::AddValueToStack(const float value)
  532. {
  533. QueueScript* script = GetScriptByScriptId(m_CurrentScriptId);
  534. if(script != nullptr)
  535. {
  536. lua_pushnumber(script->state, value);
  537. }
  538. }