Logo

SM5 THEMING HELP

Register Log In Back To Forums

Post #1 · Posted at 2014-08-10 12:23:57pm 9.7 years ago

Offline zGHRs
zGHRs Avatar Member
36 Posts
China
Reg. 2013-07-01

Now I'm making the theme. I have met the problem at here.

I have used the code in theme configuations, I want to set the changing milestone in the game. The theme had become an error when I use this code.

ERROR:
Crash reason: HundredMilestone: 0/7

CODE in Scripts folder:
Quote

function InitUserPrefs()
if GetUserPref("HundredMilestone") == nil or GetUserPref("HundredMilestone") == "No" then
SetUserPref("HundredMilestone", "GreenCircle");
end;
end;

function HundredMilestone()
local t =
{
Name = "HundredMilestone";
LayoutType = "ShowAllInRow";
SelectType = "SelectOne";
OneChoiceForAllPlayers = false;
ExportOnChange = true;

Choices =
{ "GreenCircle","FlorescentGreenHexagon","Blue5PStar","PinkHeart","RedOrangeExplosion","waieiWAVE","PurpleDiamond","SeaGreenUniversalHexagram","RedCrossStar","YellowOctahedral","YellowOrangeOctagon","OrangeCircle","RhombusWAVE" };
LoadSelections = function(self, list, pn)
if ReadPrefFromFile("HundredMilestone") == nil or ReadPrefFromFile("HundredMilestone") == "No" then
list[1] = true;
WritePrefToFile("HundredMilestone","GreenCircle");
else

if GetUserPref("HundredMilestone") == "GreenCircle" then
list[1] = true;
end

if GetUserPref("HundredMilestone") == "FlorescentGreenHexagon" then
list[2] = true;
end

if GetUserPref("HundredMilestone") == "Blue5PStar" then
list[3] = true;
end

if GetUserPref("HundredMilestone") == "PinkHeart" then
list[4] = true;
end

if GetUserPref("HundredMilestone") == "RedOrangeExplosion" then
list[5] = true;
end

if GetUserPref("HundredMilestone") == "waieiWAVE" then
list[6] = true;
end

if GetUserPref("HundredMilestone") == "PurpleDiamond" then
list[7] = true;
end

if GetUserPref("HundredMilestone") == "SeaGreenUniversalHexagram" then
list[8] = true;
end

if GetUserPref("HundredMilestone") == "RedCrossStar" then
list[9] = true;
end

if GetUserPref("HundredMilestone") == "YellowOctahedral" then
list[10] = true;
end

if GetUserPref("HundredMilestone") == "YellowOrangeOctagon" then
list[11] = true;
end

if GetUserPref("HundredMilestone") == "OrangeCircle" then
list[12] = true;
end

if GetUserPref("HundredMilestone") == "RhombusWAVE" then
list[0] = true;
end
end;
end;

SaveSelections = function(self, list, pn)
local val;
if list[1] then
val = "GreenCircle";
end

if list[2] then
val = "FlorescentGreenHexagon";
end

if list[3] then
val = "Blue5PStar";
end

if list[4] then
val = "PinkHeart";
end

if list[5] then
val = "RedOrangeExplosion";
end

if list[6] then
val = "waieiWAVE";
end

if list[7] then
val = "PurpleDiamond";
end

if list[8] then
val = "SeaGreenUniversalHexagram";
end

if list[9] then
val = "RedCrossStar";
end

if list[10] then
val = "YellowOctahedral";
end

if list[11] then
val = "YellowOrangeOctagon";
end

if list[12] then
val = "OrangeCircle";
end

if list[0] then
val = "RhombusWAVE";
end
WritePrefToFile("HundredMilestone",val);
end;
};

setmetatable( t, t );
return t;
end
However, I have setted the code in metrics.ini to direct for HundredMilestone(). And also have made the code in Combo 100Milestone folder. I want to ask a question. What's the problem? How to avoid this crash reason (Crash reason: HundredMilestone: 0/7) when the theme have included for the code of above?

Post #2 · Posted at 2014-08-10 01:24:14pm 9.7 years ago

Offline Kyzentun
Kyzentun Avatar Member
3,209 Posts
United States
Reg. 2008-02-20

"I'm honestly pissed off."
It looks like you're trying to make a lua option row.
1. Use the latest nightly build. The text of the error that is reported has changed somewhat.
2. The documentation example for lua option rows is Docs/Themerdocs/Examples/OptionRowHandlerLua.lua. Read that file so you'll understand how to make a lua option row.
3. The selections list for a lua option row is one-indexed. This means that the index starts at one and goes up. Your code is zero-indexed, which means it starts at zero and goes up. This is probably your mistake.
4. Use tables and loops so that you have less code to read. I have included a rewrite that uses loops and tables as an example.
5. "setmetatable(t, t)" does nothing whatsoever in this example. Don't do it.
6. Many of your semicolons do nothing. I guess you don't know lua very well. Spend some time reading The Lua 5.1 Reference Manual. You don't actually need semicolons at all, you can use commas to separate the elements of a table.
7. There's no point in creating a variable and immediately return it. Simply create the variable in the return statement.

Rewritten code that uses loops and tables to be shorter: (I have not tried to actually test this)
Quote
function InitUserPrefs()
if GetUserPref("HundredMilestone") == nil or GetUserPref("HundredMilestone") == "No" then
SetUserPref("HundredMilestone", "GreenCircle")
end
end

-- Create the choices table up here so it can be used a bit more widely.
local milestone_choices= {
"GreenCircle","FlorescentGreenHexagon","Blue5PStar","PinkHeart","RedOrangeExplosion","waieiWAVE","PurpleDiamond",
"SeaGreenUniversalHexagram","RedCrossStar","YellowOctahedral","YellowOrangeOctagon","OrangeCircle",
"RhombusWAVE"
}
-- Create a reverse lookup table for quick conversion from name to position.
local name_to_list_pos= {}
for i, name in ipairs(milestone_choices) do
name_to_list_pos[name]= i
end

function HundredMilestone()
return {
Name = "HundredMilestone",
LayoutType = "ShowAllInRow",
SelectType = "SelectOne",
OneChoiceForAllPlayers = false,
ExportOnChange = true,

Choices = milestone_choices,
LoadSelections = function(self, list, pn)
if ReadPrefFromFile("HundredMilestone") == nil or ReadPrefFromFile("HundredMilestone") == "No" then
list[1] = true
WritePrefToFile("HundredMilestone","GreenCircle")
else
local pref= GetUserPref("HundredMilestone")
-- If there's an invalid value in the pref file, it won't be in the reverse lookup table.
if name_to_list_pos[pref] then
list[name_to_list_pos[pref]]= true
else
-- Something must be chosen, so set the first one to true if nothing was chosen.
list[1]= true
end
end
end,

SaveSelections = function(self, list, pn)
local val= "GreenCircle"
for i, choice in ipairs(list) do
if choice then
val= milestone_choices[i]
end
end
WritePrefToFile("HundredMilestone",val)
end,
}
end

silenttype01: Kyzentun is never harsh. He says it how it is.

GENERATION 24: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
Register Log In Back To Forums

0 User(s) Viewing This Thread (Past 15 Minutes)

©2006-2024 Zenius -I- vanisher.com -5th style- IIPrivacy Policy
Web Server: 3% · Database: 4% · Server Time: 2024-04-20 14:27:16
This page took 0.004 seconds to execute.
Theme: starlight · Language: englishuk
Reset Theme & Language