/** * scriptvar_test.script * * Assumes this script is attached to a character */ //---------------------------------------------------------- include library.utils; include java.util.StringTokenizer; //---------------------------------------------------------- trigger OnInitialize() { return SCRIPT_CONTINUE; } trigger OnHearSpeech(obj_id objSpeaker, string strText) { if (objSpeaker != self) return SCRIPT_CONTINUE; if (strText.startsWith("ahh")) { StringTokenizer st = new StringTokenizer(strText); if (st.countTokens() == 2) { string command = st.nextToken(); string id = st.nextToken(); obj_id target = utils.stringToObjId(id); if (isIdValid(target)) { if (exists(target)) { dictionary d = target.getScriptDictionary(); sendSystemMessageTestingOnly(self, "scriptDictionary for " + target + " are: " + d.toString()); } else { sendSystemMessageTestingOnly(self, "ahh " + target + " - no object"); } } else { sendSystemMessageTestingOnly(self, "ahh " + target + " - bad id"); } } } else if (strText.startsWith("ohh")) { StringTokenizer st = new StringTokenizer(strText); if (st.countTokens() == 4) { string command = st.nextToken(); string id = st.nextToken(); string var = st.nextToken(); string val = st.nextToken(); obj_id target = utils.stringToObjId(id); if (isIdValid(target)) { if (exists(target)) { dictionary d = target.getScriptDictionary(); d.put(var, val); sendSystemMessageTestingOnly(self, "Setting scriptDictionary for " + target + " " + var + "=" + val); } else { sendSystemMessageTestingOnly(self, "ohh " + target + " - no object"); } } else { sendSystemMessageTestingOnly(self, "ohh " + target + " - bad id"); } } } else if (strText.startsWith("ah")) { StringTokenizer st = new StringTokenizer(strText); if (st.countTokens() == 2) { string command = st.nextToken(); string id = st.nextToken(); obj_id target = utils.stringToObjId(id); if (isIdValid(target)) { if (exists(target)) { deltadictionary dctScriptVars = target.getScriptVars(); sendSystemMessageTestingOnly(self, "Scriptvars for " + target + " are: " + dctScriptVars.toString()); } else { sendSystemMessageTestingOnly(self, "ah " + target + " - no object"); } } else { sendSystemMessageTestingOnly(self, "ah " + target + " - bad id"); } } } else if (strText.startsWith("oh")) { StringTokenizer st = new StringTokenizer(strText); if (st.countTokens() == 4) { string command = st.nextToken(); string id = st.nextToken(); string var = st.nextToken(); string val = st.nextToken(); obj_id target = utils.stringToObjId(id); if (isIdValid(target)) { if (exists(target)) { utils.setScriptVar(target, var, val); sendSystemMessageTestingOnly(self, "Setting scriptvar for " + target + " " + var + "=" + val); } else { sendSystemMessageTestingOnly(self, "oh " + target + " - no object"); } } else { sendSystemMessageTestingOnly(self, "oh " + target + " - bad id"); } } } else if (strText == "gc") { sendSystemMessageTestingOnly(self, "telling Java to do garbage collection"); System.gc(); } else if (strText == "getGameTime") { sendSystemMessageTestingOnly(self, "getGameTime() returns " + getGameTime()); } return SCRIPT_CONTINUE; }