我正在尝试添加如图所示的菜单,但这给了我错误。Error, .lua
function loadPlayerInventory()
TBCore.Functions.TriggerServerCallback('tb-inventory:server:getPlayerInventory', function(data)
items =
inventory = data.inventory
weapons = data.weapons
local weight = 0
if inventory ~= nil then
for k, v in pairs(inventory) do
table.insert(items, inventory[k])
weight = weight + (inventory[k].amount * inventory[k].weight)
end
答案 0 :(得分:1)
public class land_calculation extends AppCompatActivity {
private LinearLayout landone, landtwo, landthree, landfour, landfive, landsix, landseven, landeight, landnine;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_land_calculation);
landone = findViewById(R.id.landone);
landtwo = findViewById(R.id.landtwo);
landthree = findViewById(R.id.landthree);
landfour = findViewById(R.id.landfour);
landfive = findViewById(R.id.landfive);
landsix = findViewById(R.id.landsix);
landseven = findViewById(R.id.landseven);
landeight = findViewById(R.id.landeight);
landnine = findViewById(R.id.landnine);
landone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(land_calculation.this, landOne.class);
startActivity(i);
}
});
landtwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(land_calculation.this, landTwo.class);
startActivity(i);
}
});
landthree.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(land_calculation.this, landThree.class);
startActivity(i);
}
});
landfour.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(land_calculation.this, landFour.class);
startActivity(i);
}
});
landfive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(land_calculation.this, landFive.class);
startActivity(i);
}
});
landsix.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(land_calculation.this, landSix.class);
startActivity(i);
}
});
landseven.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(land_calculation.this, landSeven.class);
startActivity(i);
}
});
landeight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(land_calculation.this, landEight.class);
startActivity(i);
}
});
landnine.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(land_calculation.this, landNine.class);
startActivity(i);
}
});
}
应该给您一个错误items =
,因此您甚至不应该回叫到回调。
您忘记为项目分配值。您的代码建议它应该是一个表。
屏幕截图中的错误是由索引数据(本地nil值)引起的。
"unexpected symbol near =
这是因为调用了您的回调,但是没有给出参数inventory = data.inventory
。找出原因,或者确保它不为nil。
类似
data
或
if data then
inventory = data.inventory
end
例如