otherworld.SetVariable problems - VBScript

Posted by Ceramic Weasel on Sun 15 Aug 2004 06:13 AM — 3 posts, 13,497 views.

#0
I've tried this again and again in so many different ways, and I can't figure out what I'm doing wrong. I have a piece of code up the top of my VBScript file like this:

Set Volute = world.GetWorld ("Volute")
If isempty(Volute) Then
	world.Note "--- Database is not open."
Else
	world.Note "--- Database has been accessed."
End If


And that works fine. I'm able to do things like Volute.GetVariable("Blah") and Volute.SetVariable "Blah", "Blah blah blah" without any troubles.... however, when I try to use two different Volute.SetVariable lines in the same Sub, it will only do one of them:

Sub TestMe(Winner, Loser)
	WinFile = Volute.GetVariable("Stat_" & Winner)
	LosFile = Volute.GetVariable("Stat_" & Loser)
	If isempty(WinFile) Or isempty(LosFile) Then
		world.Note "--- Cannot find variable!"
		Exit Sub
	End If
	WinStat = split(WinFile, ",")
	LosStat = split(LosFile, ",")

	world.Note "--- " & Winner & " WinStat(16): " & WinStat(16)
	world.Note "--- " & Loser & " LosStat(16): " & LosStat(16)

	WinStat(16) = cint(WinStat(16)) + 3
	LosStat(16) = cint(LosStat(16)) + 1

	world.Note "--- New " & Winner & " WinStat(16): " & WinStat(16)
	world.Note "--- New " & Loser & " LosStat(16): " & LosStat(16)

	Volute.SetVariable "Stat_" & Winner, join(WinStat, ",")
	Volute.SetVariable "Stat_" & Loser, join(LosStat, ",") '<--- DOESN'T WORK!

	world.Note "--- Stat_" & Loser
End Sub


Quote:
--- janx WinStat(16): 9
--- kodax LosStat(16): 0
--- New janx WinStat(16): 12
--- New kodax LosStat(16): 1
--- Stat_kodax

--- janx WinStat(16): 12
--- kodax LosStat(16): 0
--- New janx WinStat(16): 15
--- New kodax LosStat(16): 1
--- Stat_kodax

--- janx WinStat(16): 15
--- kodax LosStat(16): 0
--- New janx WinStat(16): 18
--- New kodax LosStat(16): 1
--- Stat_kodax

--- janx WinStat(16): 18
--- kodax LosStat(16): 0
--- New janx WinStat(16): 21
--- New kodax LosStat(16): 1
--- Stat_kodax


The strange part about it is, even if I swap the two around, "Stat_" & Loser remains the one that won't set. I've checked the variable, it's there and index 16 is 0, but won't change. Anyone know what's going on here?
Australia Forum Administrator #1
It looks strange. I suggest doing two things:

1. SetVariable returns a code, check it is zero, eg.

result = Volute.SetVariable ("Stat_" & Loser, join(LosStat, ",") )

world.Note "result = " & result


2. Check what you are setting it to, like this:


world.Note "lostat = " & join(LosStat, ",")


#2
Crisis over.

After days of pulling my hair out, i realised i was re-setting the same variable in the parent Sub after i'd called TestMe... so it was being updated, and then being set again to the original values afterwards - A product of my bad scripting. :\