這可能是一個愚蠢的問題,但我將如何去與另一種方法共享變量ammount和價格?在方法之間共享變量
[Command("sellweed")]
public void sellWeed(Client sender, Client target, int ammount, int price)
{
API.sendChatMessageToPlayer(sender, "~b~You have offered " + ammount +
" Weed to " + target + "for $" + price + ", wait for him to accept.");
API.sendChatMessageToPlayer(target, "~b~" + sender + " has offered you " + ammount +
" Weed for a price of $" + price + ", type /acceptweed to buy.");
}
[Command("acceptweed")]
public void acceptWeed(Client player)
{
checkPlayerName = API.getPlayerName(player);
string checkMoney = "SELECT Wallet FROM [playerInfo] WHERE PlayerName='" +
checkPlayerName + "'";
con.Open();
SqlCommand checkMoneyCMD = new SqlCommand(checkMoney, con);
int playerMoney = Convert.ToInt32(checkMoneyCMD.ExecuteScalar());
con.Close();
if (playerMoney < price)
{
API.sendChatMessageToPlayer(player, "You don't have enough money.");
}
else
API.sendChatMessageToPlayer(player, "You received " + ammount + " of weed.");
}
金額只有一個'm' –
定義了價格(即acceptWeed如何訪問)? –