Array must be indexed error... [SOLVED]
#1

This is solved now.

What is problem with this?
(This uses dini 1.6)

It's giving error
error 035: argument type mismatch (argument 2)
LINE: GivePlayerMoney(playerid, inputtext);

error 033: array must be indexed (variable "amount")
LINE: BankInfo = amount-inputtext;

Код:
	if(strcmp(cmdtext, "/command", true) == 0)
	{
	  new string3[286];
  	format(string3,sizeof(string3),"ASAKDJIAJIFUF:");
  	ShowPlayerDialog(playerid,7676,DIALOG_STYLE_INPUT,"title",string3,"SENT","CALL");
	return 1;
	}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	// Textfile
	// Example
	// Money=value
	// like (money=200000)
	if(dialogid == 7676)
  {
	 if(response)
		{
    print("Debug.");
    new BankInfo[286];
    new message[286];
    new amount[286];

    amount = dini_Get("company_account/money.ini", "money"); // Gets "money" value and fill it to amount
    GivePlayerMoney(playerid, inputtext);
    BankInfo = amount-inputtext; // Operation its like this (Current bank amount, wich come from "amount" MINUS "inputtext" amount = X; answer should be now filled to BankInfo now)
    format(message, sizeof(message), "You did: %sЂ", inputtext);
    SendClientMessage(playerid, COLOR_WHITE, message);

    dini_Set("company_account/money.ini", "money", BankInfo); // Open dini "money" and saves "money" value wich come from BankInfo
    }
    return 1;
  }
  return 0;
}
Reply
#2

both are defined as an array...
Reply
#3

You need to put an index in it like "amount[1]" or "inputtext[23]". You can use a variable instead of the decimals, too.
Reply
#4

Kk, cool it works. No errors on compile.
Now there is only 1 problem left.

Why line BankInfo[285] = BankInfo[285]-carcost; dont work?
It don't save anything to BankInfo...
Код:
new BankInfo[286];
    new message[286];
		new amount[286];
		new carcost = 265;
 		new vid = GetPlayerVehicleID(playerid);
		// DINI GET
		amount = dini_Get("company_account/money.ini", "money");
		// DINI GET end
		// COUNT bank minus carfixcost is X
		BankInfo[285] = BankInfo[285]-carcost;
		// COUNT bank minus carfixcost is X end
		format(message, sizeof(message), "Your car repair cost %iЂ", carcost);
		// MINUS MONEY FROM PLAYER
		GivePlayerMoney(playerid, -carcost);
		// MINUS MONEY FROM PLAYER end
    SendClientMessage(playerid, COLOR_WHITE, message);
    // DINI WRITE VALYE TO MONEY
    dini_Set("company_account/money.ini", "money", BankInfo);
    // DINI WRITE VALYE TO MONEY end
    // REPAIR VEHICLE
	  if (vid) RepairVehicle(vid);
	  // REPAIR VEHICLE end
Reply
#5

Bump, still need help with this
Reply
#6

Quote:
Originally Posted by woaha
Bump, still need help with this
Reply
#7

You need to rethink that code dude.

pawn Код:
new BankInfo[286]; // not needed
new message[286]; // 286 is overkill, the message is only like 25 characters, that's 261 wasted but all is not needed as I explain below
new amount[286]; // why a string, this is a huge waste of memory ?
new carcost = 265; //why create the var if you know the cost ?
new vid = GetPlayerVehicleID(playerid); // this is fine, you use it twice and variables are fast
amount = dini_Get("company_account/money.ini", "money"); //isn't there GetINT or something, or use "strval( dini_Get..."
BankInfo[285] = BankInfo[285]-carcost; //this isn't needed, do the math when you write it
format(message, sizeof(message), "Your car repair cost %iЂ", carcost); //could just be 265 instead of "carcost", no need to format the string really
GivePlayerMoney(playerid, -carcost); //again just minus 265 from thier current cash
SendClientMessage(playerid, COLOR_WHITE, message); //this could contain just "Your car repair cost 265" as we know the price already
dini_Set("company_account/money.ini", "money", BankInfo); //you could use IntSet or something (I don't know dini) so no need for the string (amount) like I noted above
if (vid) RepairVehicle(vid); //all good, you saved on one function call
I would do this:

pawn Код:
new
  amount, // integer
  vid = GetPlayerVehicleID(playerid);

amount = dini_Int("company_account/money.ini", "money"); // grab it as an integer, no need to mess about with strings
GivePlayerMoney(playerid, (GetPlayerMoney(playerid) -265)); // take away the cost from the players current cash, no need for variables etc
SendClientMessage(playerid, COLOR_WHITE, "Your car repair cost 265"); // send the raw message, no need to format as we know the cost.
dini_IntSet("company_account/money.ini", "money", (amount - 265)); // write the amount minus the cost back into the file
if (vid) RepairVehicle(vid);
See how much smaller and faster the code is now, I'm not trying to be a smartarse I'm trying to educate you as to why code layout and logic is important. They both do the exact same thing, the end result is the same so it makes sense to code efficiently as it's less typing (yes I'm lazy) and it makes your script run faster so less lagg and better gameplay overall.

By the way I didn't test anything, I just wrote that out and I don't know Dini so swap the names of the functions to the correct "dini_***" ones. I remember from when I used to use it that you could read a direct integer and write them also so no need to mess about with string functions.
Reply
#8

Thank you. Nice answer. Very constructive for me.
It works now perfect.

But if car cost amount come from inputtext how to do that?
Reply
#9

pawn Код:
strval( inputtext );
Wiki link.
Reply
#10

Thank you, very much. This is now solved.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)