Array must be indexed
#1

Hey, I'm having another problem.

With (part of) my script:
Код:
new Name[24]; 
GetPlayerName(playerid, Name, sizeof(Name));

if (AHouseData[HouseID][Owner] == Name)
It outputs this error:
Код:
array must be indexed (variable "Name")
Please note: that is only a tiny snippet of my code and the error is on the line
Код:
if (AHouseData[HouseID][Owner] == Name)
. I have tried everything and picked out the relevant parts of the code that I think will help you solve the issue I am facing. Thanks in advance.
Reply
#2

use string compare

Код:
if(strcmp(AHouseData[HouseID][Owner], Name) == 0)
Reply
#3

Shouldn't be using strcmp for this! Store the id of the house owner and check that.
Reply
#4

I know you said don't use strcmp but I decided to experiment before I do what you said Pottus. Here is what it outputted:
Код:
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
SetPlayerInterior(0, 10);
SetPlayerPos(0, 2260.760009, -1210.449951, 1049.020019);
Код:
				if (strcmp(AHouseData[HouseID][Owner], Name, false) == 0)
				{
					hLevel = AHouseData[HouseID][HouseLevel];
					SetPlayerVirtualWorld(playerid, 5000 + HouseID);
					SetPlayerInterior(playerid, AHouseInteriors[hLevel][InteriorID]);
					printf("SetPlayerInterior(%d, %d);", playerid, AHouseInteriors[hLevel][InteriorID]);
					SetPlayerPos(playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]);
					printf("SetPlayerPos(%d, %f, %f, %f);", playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]);

					APlayerData[playerid][CurrentHouse] = HouseID;
					SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}Use {FFFF00}/housemenu{FFFF00} to change options for your house");
					return 1;
				}
				else if (strcmp(AHouseData[HouseID][Owner], Name, false) != 0)
				{
				    printf("Else called");
This is a bigger snippet of the code but still not all of it. Why is it printing else if so many times? The player is getting teleported to the correct position and interior, I'm just not sure what is going on. Thanks in advance.
Reply
#5

Why are you using else if you can just use else in that case, you're checking if the house has owner already.
pawn Код:
if(!strcmp(AHouseData[HouseID][Owner], Name, false))
{
    hLevel = AHouseData[HouseID][HouseLevel];
    SetPlayerVirtualWorld(playerid, 5000 + HouseID);
    SetPlayerInterior(playerid, AHouseInteriors[hLevel][InteriorID]);
    printf("SetPlayerInterior(%d, %d);", playerid, AHouseInteriors[hLevel][InteriorID]);
    SetPlayerPos(playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]);
    printf("SetPlayerPos(%d, %f, %f, %f);", playerid, AHouseInteriors[hLevel][IntX], AHouseInteriors[hLevel][IntY], AHouseInteriors[hLevel][IntZ]);

    APlayerData[playerid][CurrentHouse] = HouseID;
    SendClientMessage(playerid, COLOR_WHITE, "{FFFF00}Use {FFFF00}/housemenu{FFFF00} to change options for your house");
    return 1;
}
else
{
    print("else called!");
}
Reply
#6

I'm pretty sure I changed it to else if because else provided errors and I wanted to see if anything changed. Any other things?
Reply
#7

Quote:
Originally Posted by Proxus
Посмотреть сообщение
I'm pretty sure I changed it to else if because else provided errors and I wanted to see if anything changed. Any other things?
There's no way to cause errors unless you've done something wrong on it! Provide the errors you get. Also I'd definitely recommend what Pottus said!
Reply
#8

There's no errors but why does it spam else? It shouldn't call both the playerpos and the else, they're in two different expressions
Reply
#9

Else outputs the same thing as elseif

Код:
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
Else called
SetPlayerInterior(0, 10);
SetPlayerPos(0, 2260.760009, -1210.449951, 1049.020019);
Edit: Now if the player doesn't actually own a house, it crashes GTA:SA for the player.
It still outputs else called but the last part now does this:

Код:
SetPlayerVirtualWorld(0, 5828);
SetPlayerInterior(0, 0);
SetPlayerPos(0, 0.000000, 0.000000, 0.000000);
5828 (5000 + HouseID)
827 is the last house id and the player doesn't own a house? What is going on?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)