- Joined
- Oct 12, 2011
- Messages
- 3,449
Can someone please enlight me what's causing this?
So in short I'm queuing a string into a queue.
This is the module I'm using (it's Nestharus'):
And this is the method I called:
And this is the result:
As you see, "node" and "content.first" should've referred to the same node, right? At least it's what I comprehend from the module I'm using. But, strangely, it printed different text.
I'm feeling dumb today, I may have missed something trivial here. But I'm also a bit mind blown. So please, someone enlight me what am I doing wrong here? Thanks in advance.
EDIT:
Just in case it's needed, here is the whole code:
Solved:
DialogContent => ConversationContent
So in short I'm queuing a string into a queue.
This is the module I'm using (it's Nestharus'):
JASS:
library Queue /* v1.0.0.6
************************************************************************************
*
* */uses/*
*
* */ ErrorMessage /* hiveworkshop.com/forums/submissions-414/snippet-error-message-239210/
*
************************************************************************************
*
* module Queue
*
* Description
* -------------------------
*
* NA
*
* Fields
* -------------------------
*
* readonly static integer sentinel
*
* readonly thistype first
* readonly thistype next
*
* Methods
* -------------------------
*
* static method create takes nothing returns thistype
* method destroy takes nothing returns nothing
* - May only destroy queues
*
* method enqueue takes nothing returns thistype
* method pop takes nothing returns nothing
*
* method clear takes nothing returns nothing
*
* debug static method calculateMemoryUsage takes nothing returns integer
* debug static method getAllocatedMemoryAsString takes nothing returns string
*
************************************************************************************/
module Queue
private static thistype collectionCount = 0
private static thistype nodeCount = 0
debug private boolean isNode
debug private boolean isCollection
private thistype last
private thistype _next
method operator next takes nothing returns thistype
debug call ThrowError(this == 0, "Queue", "next", "thistype", this, "Attempted To Go Out Of Bounds.")
debug call ThrowError(not isNode, "Queue", "next", "thistype", this, "Attempted To Read Invalid Node.")
return _next
endmethod
private thistype _first
method operator first takes nothing returns thistype
debug call ThrowError(this == 0, "Queue", "first", "thistype", this, "Attempted To Read Null Queue.")
debug call ThrowError(not isCollection, "Queue", "first", "thistype", this, "Attempted To Read Invalid Queue.")
return _first
endmethod
static method operator sentinel takes nothing returns integer
return 0
endmethod
private static method allocateCollection takes nothing returns thistype
local thistype this = thistype(0)._first
if (0 == this) then
debug call ThrowError(collectionCount == 8191, "Queue", "allocateCollection", "thistype", 0, "Overflow.")
set this = collectionCount + 1
set collectionCount = this
else
set thistype(0)._first = _first
endif
return this
endmethod
private static method allocateNode takes nothing returns thistype
local thistype this = thistype(0)._next
if (0 == this) then
debug call ThrowError(nodeCount == 8191, "Queue", "allocateNode", "thistype", 0, "Overflow.")
set this = nodeCount + 1
set nodeCount = this
else
set thistype(0)._next = _next
endif
return this
endmethod
static method create takes nothing returns thistype
local thistype this = allocateCollection()
debug set isCollection = true
set _first = 0
return this
endmethod
method enqueue takes nothing returns thistype
local thistype node = allocateNode()
debug call ThrowError(this == 0, "Queue", "enqueue", "thistype", this, "Attempted To Enqueue On To Null Queue.")
debug call ThrowError(not isCollection, "Queue", "enqueue", "thistype", this, "Attempted To Enqueue On To Invalid Queue.")
debug set node.isNode = true
if (_first == 0) then
set _first = node
else
set last._next = node
endif
set last = node
set node._next = 0
return node
endmethod
method pop takes nothing returns nothing
local thistype node = _first
debug call ThrowError(this == 0, "Queue", "pop", "thistype", this, "Attempted To Pop Null Queue.")
debug call ThrowError(not isCollection, "Queue", "pop", "thistype", this, "Attempted To Pop Invalid Queue.")
debug call ThrowError(node == 0, "Queue", "pop", "thistype", this, "Attempted To Pop Empty Queue.")
debug set node.isNode = false
set _first = node._next
set node._next = thistype(0)._next
set thistype(0)._next = node
endmethod
method clear takes nothing returns nothing
debug local thistype node = _first
debug call ThrowError(this == 0, "Queue", "clear", "thistype", this, "Attempted To Clear Null Queue.")
debug call ThrowError(not isCollection, "Queue", "clear", "thistype", this, "Attempted To Clear Invalid Queue.")
static if DEBUG_MODE then
loop
exitwhen node == 0
set node.isNode = false
set node = node._next
endloop
endif
if (_first == 0) then
return
endif
set last._next = thistype(0)._next
set thistype(0)._next = _first
set _first = 0
endmethod
method destroy takes nothing returns nothing
debug call ThrowError(this == 0, "Queue", "destroy", "thistype", this, "Attempted To Destroy Null Queue.")
debug call ThrowError(not isCollection, "Queue", "destroy", "thistype", this, "Attempted To Destroy Invalid Queue.")
static if DEBUG_MODE then
debug call clear()
debug set isCollection = false
else
if (_first != 0) then
set last._next = thistype(0)._next
set thistype(0)._next = _first
endif
endif
set _first = thistype(0)._first
set thistype(0)._first = this
endmethod
static if DEBUG_MODE then
static method calculateMemoryUsage takes nothing returns integer
local thistype start = 1
local thistype end = 8191
local integer count = 0
loop
exitwhen integer(start) > integer(end)
if (integer(start) + 500 > integer(end)) then
return count + checkRegion(start, end)
else
set count = count + checkRegion(start, start + 500)
set start = start + 501
endif
endloop
return count
endmethod
private static method checkRegion takes thistype start, thistype end returns integer
local integer count = 0
loop
exitwhen integer(start) > integer(end)
if (start.isNode) then
set count = count + 1
endif
if (start.isCollection) then
set count = count + 1
endif
set start = start + 1
endloop
return count
endmethod
static method getAllocatedMemoryAsString takes nothing returns string
local thistype start = 1
local thistype end = 8191
local string memory = null
loop
exitwhen integer(start) > integer(end)
if (integer(start) + 500 > integer(end)) then
if (memory != null) then
set memory = memory + ", "
endif
set memory = memory + checkRegion2(start, end)
set start = end + 1
else
if (memory != null) then
set memory = memory + ", "
endif
set memory = memory + checkRegion2(start, start + 500)
set start = start + 501
endif
endloop
return memory
endmethod
private static method checkRegion2 takes thistype start, thistype end returns string
local string memory = null
loop
exitwhen integer(start) > integer(end)
if (start.isNode) then
if (memory == null) then
set memory = I2S(start)
else
set memory = memory + ", " + I2S(start) + "N"
endif
endif
if (start.isCollection) then
if (memory == null) then
set memory = I2S(start)
else
set memory = memory + ", " + I2S(start) + "C"
endif
endif
set start = start + 1
endloop
return memory
endmethod
endif
endmodule
endlibrary
And this is the method I called:
JASS:
static method addContent takes string text, integer portrait returns nothing
local DialogContent node = content.enqueue()
set node.text = text
set node.portrait = portrait
call BJDebugMsg("========ADD")
call BJDebugMsg("node: " + I2S(node))
call BJDebugMsg("first: " + I2S(content.first))
call BJDebugMsg("node text: " + node.text)
call BJDebugMsg("first text: " + content.first.text)
endmethod
And this is the result:
As you see, "node" and "content.first" should've referred to the same node, right? At least it's what I comprehend from the module I'm using. But, strangely, it printed different text.
I'm feeling dumb today, I may have missed something trivial here. But I'm also a bit mind blown. So please, someone enlight me what am I doing wrong here? Thanks in advance.
EDIT:
Just in case it's needed, here is the whole code:
JASS:
library ConversationBox uses PanelPlatform
globals
private constant real CONVBOX_WIDTH = 1346.0
private constant real CONVBOX_HEIGHT = 300.0
private constant real CONVBOX_BOUND = 55.0
private constant real CONVCONT_H_OFFSET = 1.0
private constant real CONVCONT_V_OFFSET = 5.0
private constant real CONVCONT_SPACE_WIDTH = 10.0 // px
private constant real CONVCONT_SIZE = 0.2
private constant integer CONVCONT_MAX_LENGTH = 50
endglobals
private struct ConversationContent extends array
string text
integer portrait
implement Queue
endstruct
private struct ConversationChar extends array
PanelPlatform plat
implement Queue
endstruct
struct ConversationBox2 extends array
static ConversationChar char
static ConversationChar current
static ConversationContent content
static ConversationContent play
static Panel box
static real delay
static integer index
private static timer Timer = CreateTimer()
private static real CharX = -(CONVBOX_WIDTH-CONVBOX_BOUND)/2
private static real CharY = (CONVBOX_HEIGHT-CONVBOX_BOUND)/2
private static method CharCorrection takes string s returns string
if s == "\"" or s == "''" then // Text macro can't have " as parameter so work it around
return "qm"
elseif StringCase(s, false) != s then // If upper case (game cache isn't case sensitive)
return s+"2"
else
return s
endif
endmethod
private static method GetCharTexture takes string s returns integer
return GetStoredInteger(Cache, "ImmortalTexture", s)
endmethod
private static method GetCharWidth takes string s returns real
return GetStoredReal(Cache, "ImmortalWidth", s)
endmethod
private static method animate takes nothing returns nothing
local DialogContent node = content.first
local string s = SubString(play.text, index, index + 1)
local real offset
call BJDebugMsg("play: " + I2S(play))
call BJDebugMsg("string: " + play.text)
call BJDebugMsg("char: " + s)
if StringLength(s) > 0 then
if s == " " then
set offset = CONVCONT_SPACE_WIDTH*CONVCONT_SIZE
else
set s = CharCorrection(s)
set offset = GetCharWidth(s)*CONVCONT_SIZE
endif
set CharX = CharX+offset+CONVCONT_H_OFFSET
set current.plat.texture = GetCharTexture(s)
call current.plat.move(CharX, CharY, 1)
call current.plat.show(true)
//call current.plat.refresh()
if CharX > (CONVBOX_WIDTH-CONVBOX_BOUND)/2 then
set CharX = -(CONVBOX_WIDTH-CONVBOX_BOUND)/2
set CharY = CharY - CONVCONT_V_OFFSET
endif
set current = current.next
set index = index + 1
if current != 0 then
call TimerStart(Timer, delay, false, function thistype.animate)
endif
endif
endmethod
static method clearContent takes nothing returns nothing
call content.clear()
endmethod
static method addContent takes string text, integer portrait returns nothing
local DialogContent node = content.enqueue()
set node.text = text
set node.portrait = portrait
call BJDebugMsg("========ADD")
call BJDebugMsg("node: " + I2S(node))
call BJDebugMsg("first: " + I2S(content.first))
call BJDebugMsg("node text: " + node.text)
call BJDebugMsg("first text: " + content.first.text)
endmethod
static method start takes nothing returns nothing
local ConversationChar node = char.first
call BJDebugMsg("========START")
loop
exitwhen node == 0
call node.plat.show(false)
set node = node.next
endloop
set CharX = -(CONVBOX_WIDTH-CONVBOX_BOUND)/2
set CharY = (CONVBOX_HEIGHT-CONVBOX_BOUND)/2
set current = char.first
set play = content.first
call BJDebugMsg("play2: " + play.text)
call BJDebugMsg("content2: " + content.first.text)
set index = 0
call box.show(true)
call TimerStart(Timer, delay, false, function thistype.animate)
endmethod
static method next takes nothing returns nothing
local ConversationChar node = char.first
set play = play.next
loop
exitwhen node == 0
call node.plat.show(false)
set node = node.next
endloop
endmethod
private static method onInit takes nothing returns nothing
local ConversationChar node
local integer i = 0
set char = ConversationChar.create()
set content = ConversationContent.create()
set box = Panel.create('h01C', 'B00N', 0, -200.0, 0)
set box.scale = 0.5
loop
exitwhen i == CONVCONT_MAX_LENGTH
set node = char.enqueue()
set node.plat = PanelPlatform.create(box, 'hTED', 'ALPH', 0, 0, 1)
set i = i + 1
endloop
call box.show(false)
set delay = 0.2
call addContent("Hello World!", 'ALPH')
call start()
endmethod
endstruct
endlibrary
Solved:
DialogContent => ConversationContent
Last edited: