I'm working on a script that takes a string a limits the number of character per line. The coding appears correct but it only displays the first 2 lines and stops.
Here is my script:
Hidden information:
JASS:
//Standard FunctionsfunctionMyBooltakesnothingreturnsbooleanreturntrueendfunctionfunctionWaitForPlayerEvent_H2PtakeshandlehreturnsplayerreturnhendfunctionfunctionWaitForPlayerEvent_H2FtakeshandlehreturnsforcereturnhendfunctionfunctionWaitForPlayerEvent_PE2Itakesplayereventpreturnsintegeriftruethenreturnpendifreturn0endfunctionfunctionWaitForPlayerEvent_EnumtakesnothingreturnsnothingcallTriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, GetEnumPlayer(), ConvertPlayerEvent(bj_forceCountPlayers))
endfunctionfunctionWaitForPlayerEventtakeshandlewhichForceOrPlayer, playereventwhichPlayerEvent, boolexprcondition, realintervalreturnsnothinglocaltriggerbj_temp = bj_delayedSuspendDecayTriglocaltriggertlocaltriggerconditionclocalplayerwhichPlayer = WaitForPlayerEvent_H2P(whichForceOrPlayer)
localforcewhichForce = WaitForPlayerEvent_H2F(whichForceOrPlayer)
ifwhichForceOrPlayer == nullorwhichPlayerEvent == nullthensetwhichForce = nullreturnelseifinterval < 0thensetinterval = 0endifsett = CreateTrigger()
setbj_delayedSuspendDecayTrig = tsetbj_forceCountPlayers = WaitForPlayerEvent_PE2I(whichPlayerEvent)
callForForce(whichForce, functionWaitForPlayerEvent_Enum)
callTriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, whichPlayer, whichPlayerEvent)
ifcondition != nullthensetc = TriggerAddCondition(bj_delayedSuspendDecayTrig, condition)
endifsetbj_delayedSuspendDecayTrig = bj_temploopcallTriggerSleepAction(interval)
exitwhenGetTriggerExecCount(t) != 0endloopifcondition != nullthencallTriggerRemoveCondition(t, c)
setc = nullendifcallDestroyTrigger(t)
sett = nullsetwhichForce = nullendfunction//End of Standard Functions//=============================================// The Parser (Takes a String, Seperates words, Returns word you wanted)// by DKSlayer//=============================================functionParsertakesstringChatMsg, integerWordreturnsstring//Required VariableslocalstringarrayChkstrlocalintegerLast = 0localintegerA = 1localintegerI = 0localintegerLength = 1//Finds the Length of Stringloopexitwhen((SubStringBJ(ChatMsg,1,Length) == ChatMsg))
setLength = Length + 1endloop//Pulls Words and places them each in there own Variableloopif(SubStringBJ(ChatMsg,A,A) == " ") thensetChkstr[i] = SubStringBJ(ChatMsg, (Last + 1), (A - 1))
setLast = AsetI = I + 1elseif(A == Length) thensetChkstr[i] = SubStringBJ(ChatMsg, (Last + 1), A)
endifsetA = A + 1exitwhen(A>Length)
exitwhen((Word+1)==I)
endloop//Returns wanted wordreturnChkstr[Word]
endfunction//Set up a new questfunctionSetupQuesttakesstringtitle, stringdescription, stringpathreturnsquestlocalquestqsetq = CreateQuest()
callQuestSetTitle(q,title)
callQuestSetCompleted(q, false)
callQuestSetDiscovered(q, true)
callQuestSetEnabled(q, false)
callQuestSetRequired(q, true)
callQuestSetDescription(q, description)
callQuestSetIconPath(q, path)
returnqendfunction//Sets Quest ObjectivesfunctionSetQuestObjectivestakesquestq, stringquestrequirmentreturnsquestitemlocalquestitemqisetqi = QuestCreateItem(q)
callQuestItemSetDescription(qi,questrequirment)
callQuestItemSetCompleted(qi, false)
returnqiendfunctionfunctionStartQuesttakesplayerp, stringt, integerwordcountreturnsnothinglocalintegerlines = 16localintegercurrentline = 1localintegercurrentword = 1localstringtemp1 = ""localstringtemp2 = ""localintegerdone = 0loopexitwhen (currentword>wordcount)
loopexitwhen (done==1)
if (StringLength(temp1)<27) thensettemp2 = temp1settemp1 = temp1 + Parser(t, currentword) + " "setcurrentword = currentword+1elsesettemp1 = temp2setdone = 1setcurrentword = currentword-1endifendloopcallDisplayTimedTextToForce( GetForceOfPlayer(p), 10000000000, temp1 )
setcurrentline = currentline+1settemp1=""if (currentline == lines) thencallDisplayTimedTextToPlayer( p, 0, 0, 1000000000.00, "(|c00FF0000Press ESC to continue.|r)")
callWaitForPlayerEvent(p, EVENT_PLAYER_END_CINEMATIC, Condition(functionMyBool), 1.00)
setcurrentline = 1endifsetdone=0endloopendfunction
A Threat Within I hope you strapped your belt on tight, young <Class>, because there is work to do here in Northshire.And I don't mean farming.The Stormwind guards are hard pressed to keep the peace here, with so many of us in distant lands and so many threats pressing close. And so we're enlisting the aid of anyone willing to defend their home. And their alliance.If you're here to answer the call, then speak with my superior, Marshal McBride. He's inside the abbey behind me.Quest Objectives Speak with Marshal McBride.
Erm, I'm not sure how you got it to run. The variable used for the index for Chkstr is not declared. Assuming you've already fixed that, however, I think the issue is that the thread is hitting it's execution limit. Throw a polled wait in after the second loop in Parser and it should be fine, after looping through what looks like more than 500 characters, for every word I'm not surprised if it's stopping. Also you can probably increase the number of characters per line since you won't be able to fit that many 16 lines. (27*16) = 432
Edit: What you should really do instead, is parse the entire thing once and then just pull the words you want. Give me a few minutes and I should be able to have that done easily enough.
Edit 2: Ok, I basically just stuck all the Parser code into the StartQuest function, so now it only loops through the text once saving processor time and not killing the thread; I left the Parser function as it is in case you still have a use for it.
Linera's Functions
JASS:
//Standard FunctionsfunctionMyBooltakesnothingreturnsbooleanreturntrueendfunctionfunctionWaitForPlayerEvent_H2PtakeshandlehreturnsplayerreturnhendfunctionfunctionWaitForPlayerEvent_H2FtakeshandlehreturnsforcereturnhendfunctionfunctionWaitForPlayerEvent_PE2Itakesplayereventpreturnsintegeriftruethenreturnpendifreturn0endfunctionfunctionWaitForPlayerEvent_EnumtakesnothingreturnsnothingcallTriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, GetEnumPlayer(), ConvertPlayerEvent(bj_forceCountPlayers))
endfunctionfunctionWaitForPlayerEventtakeshandlewhichForceOrPlayer, playereventwhichPlayerEvent, boolexprcondition, realintervalreturnsnothinglocaltriggerbj_temp = bj_delayedSuspendDecayTriglocaltriggertlocaltriggerconditionclocalplayerwhichPlayer = WaitForPlayerEvent_H2P(whichForceOrPlayer)
localforcewhichForce = WaitForPlayerEvent_H2F(whichForceOrPlayer)
ifwhichForceOrPlayer == nullorwhichPlayerEvent == nullthensetwhichForce = nullreturnelseifinterval < 0thensetinterval = 0endifsett = CreateTrigger()
setbj_delayedSuspendDecayTrig = tsetbj_forceCountPlayers = WaitForPlayerEvent_PE2I(whichPlayerEvent)
callForForce(whichForce, functionWaitForPlayerEvent_Enum)
callTriggerRegisterPlayerEvent(bj_delayedSuspendDecayTrig, whichPlayer, whichPlayerEvent)
ifcondition != nullthensetc = TriggerAddCondition(bj_delayedSuspendDecayTrig, condition)
endifsetbj_delayedSuspendDecayTrig = bj_temploopcallTriggerSleepAction(interval)
exitwhenGetTriggerExecCount(t) != 0endloopifcondition != nullthencallTriggerRemoveCondition(t, c)
setc = nullendifcallDestroyTrigger(t)
sett = nullsetwhichForce = nullendfunction//End of Standard Functions//=============================================// The Parser (Takes a String, Seperates words, Returns word you wanted)// by DKSlayer//=============================================functionParsertakesstringChatMsg, integerWordreturnsstring//Required VariableslocalstringarrayChkstrlocalintegerLast = 0localintegerA = 1localintegerI = 0localintegerLength = 1//Finds the Length of Stringloopexitwhen((SubStringBJ(ChatMsg,1,Length) == ChatMsg))
setLength = Length + 1endloop//Pulls Words and places them each in there own Variableloopif(SubStringBJ(ChatMsg,A,A) == " ") thensetChkstr[i] = SubStringBJ(ChatMsg, (Last + 1), (A - 1))
setLast = AsetI = I + 1elseif(A == Length) thensetChkstr[i] = SubStringBJ(ChatMsg, (Last + 1), A)
endifsetA = A + 1exitwhen(A>Length)
exitwhen((Word+1)==I)
endloopcallTriggerSleepAction(0)
//Returns wanted wordreturnChkstr[Word]
endfunction//Set up a new questfunctionSetupQuesttakesstringtitle, stringdescription, stringpathreturnsquestlocalquestqsetq = CreateQuest()
callQuestSetTitle(q,title)
callQuestSetCompleted(q, false)
callQuestSetDiscovered(q, true)
callQuestSetEnabled(q, false)
callQuestSetRequired(q, true)
callQuestSetDescription(q, description)
callQuestSetIconPath(q, path)
returnqendfunction//Sets Quest ObjectivesfunctionSetQuestObjectivestakesquestq, stringquestrequirmentreturnsquestitemlocalquestitemqisetqi = QuestCreateItem(q)
callQuestItemSetDescription(qi,questrequirment)
callQuestItemSetCompleted(qi, false)
returnqiendfunctionfunctionStartQuesttakesplayerp, stringt, integerwordcountreturnsnothinglocalintegerlines = 16localintegercurrentline = 1localintegercurrentword = 1localstringtemp1 = ""localstringtemp2 = ""localintegerdone = 0// BEGIN PARSER SCRIPT //localstringarrayChkstrlocalintegerLast = 0localintegerA = 1localintegerI = 0localintegerLength = 1//Finds the Length of Stringloopexitwhen((SubStringBJ(t,1,Length) == t))
setLength = Length + 1endloop//Pulls Words and places them each in there own Variableloopif(SubStringBJ(t,A,A) == " ") thensetChkstr[i] = SubStringBJ(t, (Last + 1), (A - 1))
setLast = AsetI = I + 1elseif(A == Length) thensetChkstr[i] = SubStringBJ(t, (Last + 1), A)
endifsetA = A + 1exitwhen(A>Length)
exitwhen((wordcount)==I)
endloop// END PARSER SCRIPT //loopexitwhen (currentword>wordcount)
loopexitwhen (done==1)
if (StringLength(temp1)<45) thensettemp2 = temp1settemp1 = temp1 + Chkstr[currentword] + " "setcurrentword = currentword+1elsesettemp1 = temp2setdone = 1setcurrentword = currentword-1endifendloopcallDisplayTimedTextToForce( GetForceOfPlayer(p), 10000000000, temp1 )
setcurrentline = currentline+1settemp1=""if (currentline == lines) thencallDisplayTimedTextToPlayer( p, 0, 0, 1000000000.00, "(|c00FF0000Press ESC to continue.|r)")
callWaitForPlayerEvent(p, EVENT_PLAYER_END_CINEMATIC, Condition(functionMyBool), 1.00)
setcurrentline = 1endifsetdone=0endloopendfunction
Edit 3: Forget what I said earlier about the index not being declared I'm guessing that there's something causing the 'I' to be 'i' because it's trying to italicize the text. And about not having enough lines, I didn't realize it was supposed to allow you to get more text.
Edit 4: Regardless of unuse, Parser is modified to use TriggerSleepAction(0) as suggested by Blade.dk...