这是第一次在Stack Overflow上访问,但肯定在这里找到了很多有用的信息!
当前,我正在尝试根据当前选择来确定如何选择表格中的下一项或上一项。
我当前的表格如下:
maleSkins = { 7,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,32,33,34,35,
36,37,43,44,45,46,47,48,49,51,52,57,58,59,60,61,66,67,72,73,80,82,83,
84,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,120,121,122,123,124,125,126,127,128,132,
133,134,135,136,137,142,143,144,146,147,153,154,156,159,160,161,162,
168,170,173,174,175,176,177,179,180,181,182,183,184,185,186,187,188,
189,200,202,203,204,206,210,212,213,217,220,221,222,223,227,228,229,
230,234,235,236,239,240,241,242,247,248,249,250,252,254,258,259,260,261,262 }
femaleSkins = { 9,10,11,12,13,31,38,39,40,41,53,54,55,56,69,76,77,88,89,90,91,92,
93,129,130,131,138,139,140,141,145,148,151,152,157,190,191,192,193,195,
196,197,198,199,201,207,211,214,215,216,218,219,224,225,226,232,233,237,238,243,244,245,246,251,256,257 }
maleSkins表中的默认选择为“ 7”,当他们为性别选择“ female”时,我将使用femaleSkins表。
当前我的函数调用如下所示
function selSkin(button,state)
if button ~= "left" and state ~= "up" then
return
end
if source == createChar.maleButt then
femaleSkin = false
maleSkin = true
elseif source == createChar.femaleButt then
maleSkin = false
femaleSkin = true
end
if source == createChar.nextSkin then
if maleSkin == true then
newModel = table.concat(maleSkins,)
elseif femaleSkin == true then
end
elseif source == createChar.prevSkin then
if maleSkin == true then
elseif femaleSkin == true then
end
end
end
因此,我试图在“ createChar.nextSkin”和“ createChar.prevSkin”内部基于当前皮肤对表进行排序,但是我不确定如何进行操作。
如果有人能给我做这些的基础,我会很乐意,剩下的我会自己做!
(注意:我将使用预定义变量来实现此目的)
maleSkin = true
femaleSkin = true
curSkin = 7
newModel = nil
答案 0 :(得分:1)
首先欢迎堆栈溢出:)
我注意到的一件小事:如果角色是男性或女性,则有两个变量要存储。这允许4种组合,其中2种没有意义。您也可以只使用一个变量,例如 <template>
<div id="cyto" ref="cyto"></div>
</template>
<script>
import cytoscape from "cytoscape";
export default {
name: "HelloWorld",
data: function() {
return {
cy: null
};
},
props: {
msg: String
},
mounted() {
let cy = cytoscape({
container: this.$refs.cyto,
elements: [
// list of graph elements to start with
{
// node a
data: { id: "a" }
},
{
// node b
data: { id: "b" }
},
{
// edge ab
data: { id: "ab", source: "a", target: "b" }
}
],
style: [
// the stylesheet for the graph
{
selector: "node",
style: {
"background-color": "#666",
label: "data(id)"
}
},
{
selector: "edge",
style: {
width: 3,
"line-color": "#ccc",
"target-arrow-color": "#ccc",
"target-arrow-shape": "triangle"
}
}
],
layout: {
name: "grid",
rows: 1
}
});
//this line below breaks the browser
this.cy = cy;
}
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
#cyto {
height: 100%;
display: block;
border: 1px solid blue;
}
</style>
,如果该变量为假,则使用女性皮肤。另外,您可以只做maleSkin
和skinType = 'male'
(Lua实习生字符串,所以这和比较整数一样快)
现在,除非您打算拥有几百万个或更多的皮肤,否则您可以遍历表以查找当前皮肤,然后使用上一个。
skinType = 'female'
现在,要获得下一个皮肤,您可以function skinOffset(skin, skinList, offset)
for i,current_skin in ipairs(skinList) do
if current_skin == skin then
return skinList[i + offset]
else
end
end
,对上一个皮肤skinOffset(curSkin, maleSkins, 1)
。
答案 1 :(得分:0)
将表索引另外保存在全局变量中。
有几种方法,例如skinIndex = 1
,您的代码可能如下所示:
if source == createChar.nextSkin then
newModel = maleSkin and maleSkins[skinIndex + 1] or femaleSkins[skinIndex + 1]
elseif source == createChar.prevSkin then
newModel = maleSkin and maleSkins[skinIndex - 1] or femaleSkins[skinIndex - 1]
end
但是您必须提防skinIndex
<1或> #maleSkins
/ #femaleSkins