Brenn
November 17th, 2008, 05:48
I'm pulling my hair out here.
Background. There are basically 3 kinds of rolls in Reign-
Normal roll - Roll your pool of d10's, sort into sets and go.
Expert Die- Set the value of your expert die prior to rolling the rest of your pool.
Master Die- Set the value of your master die after seeing the results from the roll of the rest of your pool.
Ok, I have a dialog for both of the Master and Expert die rolls, the Expert comes up prior to throwDice and the Master afterwards (with the results shown at the bottom of the dialog).
What is happening, is purely at (seemingly?) random times, after making the Master Die selection FG crashes. It does not do it with any other types of rolls. I don't know what the heck is going on, but I'm going to post a ton of code and hope someone can clue me in on something I've missed. Here goes, the whole roll process starts with processOneRoll in OneRollEngine.lua.
OneRollEngine.lua
function getOneRoll()
local oneRoll = {};
oneRoll.tableType = "oneroll";
oneRoll.validate = true;
oneRoll.owner = "";
oneRoll.identity = "";
oneRoll.skill = "";
oneRoll.stat = "";
oneRoll.mastery = "basic";
oneRoll.mdVal = 0;
oneRoll.pool = 0;
oneRoll.poolMod = 0;
oneRoll.dH = 0;
oneRoll.dW = 0;
oneRoll.results = {};
oneRoll.sets = {};
return oneRoll;
end
comment = [[
function createRoll(owner, skill, stat, mastery, pool, poolmodifier, difficultyH, difficultyW)
local oneRoll = getOneRoll();
oneRoll.identity = owner;
oneRoll.skill = skill;
oneRoll.stat = stat;
oneRoll.mastery = mastery;
oneRoll.pool = pool;
oneRoll.poolMod = poolmodifier;
oneRoll.dH = difficultyH;
oneRoll.dW = difficultyW;
processOneRoll(oneRoll);
end
--]]
function processOneRoll(oneRoll)
oneRoll.owner = User.getUsername();
oneRoll.index = table.maxn(pendingRolls)+1;
table.insert(pendingRolls, oneRoll);
if string.lower(oneRoll.mastery) == "expert" then
getExpertDie(oneRoll);
else
rollOneRoll(oneRoll);
end
end
function rollOneRoll(oneRoll)
local tempDieList = {};
for i = 1, (oneRoll.pool + oneRoll.poolMod) do
tempDieList[i] = "d10";
end
ChatManager.control.throwDice("oneroll", tempDieList, 0, "", oneRoll);
--while not testBool do
--end
end
function getExpertDie(oneRoll)
needMasterDie = false;
needExpertDie = true;
bonusDieDialog.setVisible(true);
bonusDieDialog.getBonusDie(oneRoll);
end
function getMasterDie(oneRoll)
needExpertDie = false;
needMasterDie = true;
bonusDieDialog.setVisible(true);
bonusDieDialog.getBonusDie(oneRoll);
end
function dialogSelectionMade(oneRoll)
--There might be a crash problem in this area.
if oneRoll.mastery == "expert" then
rollOneRoll(oneRoll);
else
pushOneRoll(oneRoll);
end
end
function getSets(results, mdVal, mdType)
local sets = {};
local dieResults = results;
table.sort(dieResults, function(a,b) return a > b end);
local done = false;
local setindex = 1;
sets[setindex]={};
local lastheight = dieResults[1];
local widthcounter = 0;
for i = 1, 10 do
for j = 1, table.maxn(dieResults) do
if i == dieResults[j] then
widthcounter = widthcounter + 1;
end
end
if widthcounter > 0 then
sets[setindex]={};
sets[setindex]["width"] = widthcounter;
sets[setindex]["height"] = i;
if mdVal == i then
if mdType == "basic" then
sets[setindex]["hasMD"] = false;
sets[setindex]["hasED"] = false;
elseif mdType == "expert" then
sets[setindex]["hasMD"] = false;
sets[setindex]["hasED"] = true;
elseif mdType == "master" then
sets[setindex]["hasMD"] = true;
sets[setindex]["hasED"] = false;
end
else
sets[setindex]["hasMD"] = false;
sets[setindex]["hasED"] = false;
end
widthcounter = 0;
setindex = setindex + 1;
end
end
local setString = "Sets For This Roll: ";
for i, v in ipairs(sets) do
if v then
setString = setString .. v.width .. "x" .. v.height ..", ";
end
end
print(setString);
return sets;
end
function registerTrackerControl(control)
tracker = control;
if bonusDieDialog then
bonusDieDialog.setParent(tracker.onerolllist);
end
end
function registerDialogControl(control)
bonusDieDialog = control;
if tracker then
bonusDieDialog.setParent(tracker.onerolllist);
end
end
function pushOneRoll(oneRoll)
if oneRoll.mdVal > 0 then
table.insert(oneRoll.results, oneRoll.mdVal);
end
oneRoll.sets = getSets(oneRoll.results, oneRoll.mdVal, oneRoll.mastery);
tracker.onerolllist.setNewRoll(oneRoll);
if User.isHost() then
local identityList = User.getAllActiveIdentities();
local recipientList = {};
for i, v in ipairs(identityList) do
table.insert(recipientList, User.getIdentityOwner(v));
end
print("Host Table Deliver");
ChatManager.deliverTable(oneRoll, recipientList);
else
print("Client Table Deliver");
ChatManager.deliverTable(oneRoll, "");
end
end
function onOneRollReceived(oneRoll)
if User.getUsername() ~= oneRoll.owner then
tracker.onerolllist.setNewRoll(oneRoll);
end
if User.isHost() then
local identityList = User.getAllActiveIdentities();
local recipientList = {};
for i, v in ipairs(identityList) do
table.insert(recipientList, User.getIdentityOwner(v));
end
for i, v in ipairs(recipientList) do
if oneRoll.owner == v then
table.remove(recipientList, i);
end
end
ChatManager.deliverTable(oneRoll, recipientList);
end
end
function deliverSetSelection(selTable)
if selTable.owner == User.getIdentityLabel() then
if User.isHost() and not selTable.wasBroadcasted then
selTable.wasBroadcasted = true;
ChatManager.deliverTable(selTable);
else
ChatManager.deliverTable(selTable, "");
end
elseif User.isHost and not selTable.wasBroadcasted then
selTable.wasBroadcasted = true;
local identityList = User.getAllActiveIdentities();
local recipientList = {};
for i, v in ipairs(identityList) do
if (User.getIdentityLabel(v) ~= selTable.owner) or selTable.hostSelect then
table.insert(recipientList, User.getIdentityOwner(v));
end
end
if table.maxn(recipientList) > 0 then
ChatManager.deliverTable(selTable, recipientList);
end
end
end
function onExternalSelection(selTable)
if (User.getIdentityLabel() ~= selTable.owner) or selTable.hostSelect then
tracker.onerolllist.onExternalSelection(selTable);
end
end
function onTrackerCommand(cmdTable)
print("ORE: onTrackerCommand: order = " .. cmdTable.order);
if cmdTable.order == "sortByWidth" then
tracker.onerolllist.setSortByWidth(true);
elseif cmdTable.order == "sortByHeight" then
tracker.onerolllist.setSortByWidth(false);
end
end
function reportRollResults(draginfo)
local oneRoll = draginfo.getCustomData();
for i = 1, draginfo.getSlotCount() do
local dieList = draginfo.getDieList();
for k, v in ipairs(dieList) do
table.insert(oneRoll.results, v.result);
end
end
if string.lower(oneRoll.mastery) == "master" then
oneRoll.sets = getSets(oneRoll.results, 0, "");
oneRoll.index = table.maxn(pendingRolls)+1;
table.insert(pendingRolls, oneRoll);
getMasterDie(oneRoll);
else
pushOneRoll(oneRoll);
end
end
function onInit()
tracker = nil;
bonusDieDialog = nil;
needMasterDie = false;
needExpertDie = false;
pendingRolls = {};
end
Background. There are basically 3 kinds of rolls in Reign-
Normal roll - Roll your pool of d10's, sort into sets and go.
Expert Die- Set the value of your expert die prior to rolling the rest of your pool.
Master Die- Set the value of your master die after seeing the results from the roll of the rest of your pool.
Ok, I have a dialog for both of the Master and Expert die rolls, the Expert comes up prior to throwDice and the Master afterwards (with the results shown at the bottom of the dialog).
What is happening, is purely at (seemingly?) random times, after making the Master Die selection FG crashes. It does not do it with any other types of rolls. I don't know what the heck is going on, but I'm going to post a ton of code and hope someone can clue me in on something I've missed. Here goes, the whole roll process starts with processOneRoll in OneRollEngine.lua.
OneRollEngine.lua
function getOneRoll()
local oneRoll = {};
oneRoll.tableType = "oneroll";
oneRoll.validate = true;
oneRoll.owner = "";
oneRoll.identity = "";
oneRoll.skill = "";
oneRoll.stat = "";
oneRoll.mastery = "basic";
oneRoll.mdVal = 0;
oneRoll.pool = 0;
oneRoll.poolMod = 0;
oneRoll.dH = 0;
oneRoll.dW = 0;
oneRoll.results = {};
oneRoll.sets = {};
return oneRoll;
end
comment = [[
function createRoll(owner, skill, stat, mastery, pool, poolmodifier, difficultyH, difficultyW)
local oneRoll = getOneRoll();
oneRoll.identity = owner;
oneRoll.skill = skill;
oneRoll.stat = stat;
oneRoll.mastery = mastery;
oneRoll.pool = pool;
oneRoll.poolMod = poolmodifier;
oneRoll.dH = difficultyH;
oneRoll.dW = difficultyW;
processOneRoll(oneRoll);
end
--]]
function processOneRoll(oneRoll)
oneRoll.owner = User.getUsername();
oneRoll.index = table.maxn(pendingRolls)+1;
table.insert(pendingRolls, oneRoll);
if string.lower(oneRoll.mastery) == "expert" then
getExpertDie(oneRoll);
else
rollOneRoll(oneRoll);
end
end
function rollOneRoll(oneRoll)
local tempDieList = {};
for i = 1, (oneRoll.pool + oneRoll.poolMod) do
tempDieList[i] = "d10";
end
ChatManager.control.throwDice("oneroll", tempDieList, 0, "", oneRoll);
--while not testBool do
--end
end
function getExpertDie(oneRoll)
needMasterDie = false;
needExpertDie = true;
bonusDieDialog.setVisible(true);
bonusDieDialog.getBonusDie(oneRoll);
end
function getMasterDie(oneRoll)
needExpertDie = false;
needMasterDie = true;
bonusDieDialog.setVisible(true);
bonusDieDialog.getBonusDie(oneRoll);
end
function dialogSelectionMade(oneRoll)
--There might be a crash problem in this area.
if oneRoll.mastery == "expert" then
rollOneRoll(oneRoll);
else
pushOneRoll(oneRoll);
end
end
function getSets(results, mdVal, mdType)
local sets = {};
local dieResults = results;
table.sort(dieResults, function(a,b) return a > b end);
local done = false;
local setindex = 1;
sets[setindex]={};
local lastheight = dieResults[1];
local widthcounter = 0;
for i = 1, 10 do
for j = 1, table.maxn(dieResults) do
if i == dieResults[j] then
widthcounter = widthcounter + 1;
end
end
if widthcounter > 0 then
sets[setindex]={};
sets[setindex]["width"] = widthcounter;
sets[setindex]["height"] = i;
if mdVal == i then
if mdType == "basic" then
sets[setindex]["hasMD"] = false;
sets[setindex]["hasED"] = false;
elseif mdType == "expert" then
sets[setindex]["hasMD"] = false;
sets[setindex]["hasED"] = true;
elseif mdType == "master" then
sets[setindex]["hasMD"] = true;
sets[setindex]["hasED"] = false;
end
else
sets[setindex]["hasMD"] = false;
sets[setindex]["hasED"] = false;
end
widthcounter = 0;
setindex = setindex + 1;
end
end
local setString = "Sets For This Roll: ";
for i, v in ipairs(sets) do
if v then
setString = setString .. v.width .. "x" .. v.height ..", ";
end
end
print(setString);
return sets;
end
function registerTrackerControl(control)
tracker = control;
if bonusDieDialog then
bonusDieDialog.setParent(tracker.onerolllist);
end
end
function registerDialogControl(control)
bonusDieDialog = control;
if tracker then
bonusDieDialog.setParent(tracker.onerolllist);
end
end
function pushOneRoll(oneRoll)
if oneRoll.mdVal > 0 then
table.insert(oneRoll.results, oneRoll.mdVal);
end
oneRoll.sets = getSets(oneRoll.results, oneRoll.mdVal, oneRoll.mastery);
tracker.onerolllist.setNewRoll(oneRoll);
if User.isHost() then
local identityList = User.getAllActiveIdentities();
local recipientList = {};
for i, v in ipairs(identityList) do
table.insert(recipientList, User.getIdentityOwner(v));
end
print("Host Table Deliver");
ChatManager.deliverTable(oneRoll, recipientList);
else
print("Client Table Deliver");
ChatManager.deliverTable(oneRoll, "");
end
end
function onOneRollReceived(oneRoll)
if User.getUsername() ~= oneRoll.owner then
tracker.onerolllist.setNewRoll(oneRoll);
end
if User.isHost() then
local identityList = User.getAllActiveIdentities();
local recipientList = {};
for i, v in ipairs(identityList) do
table.insert(recipientList, User.getIdentityOwner(v));
end
for i, v in ipairs(recipientList) do
if oneRoll.owner == v then
table.remove(recipientList, i);
end
end
ChatManager.deliverTable(oneRoll, recipientList);
end
end
function deliverSetSelection(selTable)
if selTable.owner == User.getIdentityLabel() then
if User.isHost() and not selTable.wasBroadcasted then
selTable.wasBroadcasted = true;
ChatManager.deliverTable(selTable);
else
ChatManager.deliverTable(selTable, "");
end
elseif User.isHost and not selTable.wasBroadcasted then
selTable.wasBroadcasted = true;
local identityList = User.getAllActiveIdentities();
local recipientList = {};
for i, v in ipairs(identityList) do
if (User.getIdentityLabel(v) ~= selTable.owner) or selTable.hostSelect then
table.insert(recipientList, User.getIdentityOwner(v));
end
end
if table.maxn(recipientList) > 0 then
ChatManager.deliverTable(selTable, recipientList);
end
end
end
function onExternalSelection(selTable)
if (User.getIdentityLabel() ~= selTable.owner) or selTable.hostSelect then
tracker.onerolllist.onExternalSelection(selTable);
end
end
function onTrackerCommand(cmdTable)
print("ORE: onTrackerCommand: order = " .. cmdTable.order);
if cmdTable.order == "sortByWidth" then
tracker.onerolllist.setSortByWidth(true);
elseif cmdTable.order == "sortByHeight" then
tracker.onerolllist.setSortByWidth(false);
end
end
function reportRollResults(draginfo)
local oneRoll = draginfo.getCustomData();
for i = 1, draginfo.getSlotCount() do
local dieList = draginfo.getDieList();
for k, v in ipairs(dieList) do
table.insert(oneRoll.results, v.result);
end
end
if string.lower(oneRoll.mastery) == "master" then
oneRoll.sets = getSets(oneRoll.results, 0, "");
oneRoll.index = table.maxn(pendingRolls)+1;
table.insert(pendingRolls, oneRoll);
getMasterDie(oneRoll);
else
pushOneRoll(oneRoll);
end
end
function onInit()
tracker = nil;
bonusDieDialog = nil;
needMasterDie = false;
needExpertDie = false;
pendingRolls = {};
end