Just Practicing (Objects / edit objects)
#1

Hello, I'm just practicing scripting a bit in my free time so this time I encountered "Error" that's causing the function not to do what's supposed to do. (sending the message of the current object that's placed)

EDIT:
Here is the code I'm using to create a table (it's just an object..) - just in case you want to see.
Code:
CreatePokerTable(playerid,tableid)
{
	new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z);
	
	Table[tableid][X] = Float:x;
	Table[tableid][Y] = Float:y;
	Table[tableid][Z] = Float:z;
	CreateDynamicObject(19474, x, y, z, 0.0, 0.0, 0.0, GetPlayerVirtualWorld(playerid), GetPlayerInterior(playerid), -1, 200.0);
 	//CreateObject(19474, x, y, z, 0.0, 0.0, 96.0);
 	SendClientMessage(playerid, -1, "You have sucessfuly created a table please use /edittable to place it at desired location!");
	return 1;
}
Code:
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
// stuff above
if(response == EDIT_RESPONSE_FINAL)
	{
	    new Float:x, Float:y, Float:z;
		GetObjectPos(objectid, x, y, z);
		Table[tableid][X] = Float:x;
		Table[tableid][Y] = Float:y;
		Table[tableid][Z] = Float:z;
		
		new Float:RotX,Float:RotY,Float:RotZ;
		GetObjectRot(objectid, RotX, RotY, RotZ);
		Table[tableid][RX] = Float:RotX;
		Table[tableid][RY] = Float:RotY;
		Table[tableid][RZ] = Float:RotZ;
		format(testmsg,sizeof(testmsg),"Table is set at X: %f | Y: %f | Z: %f | RX: %f | RY: %f | RZ: %f",x,y,z,RotX,RotY,RotZ);
		SendClientMessage(playerid,-1, testmsg);	
	}
       // stuff below
Message I get in .exe is the following:

Code:
[16:47:14] [debug] Run time error 20: "Invalid index parameter (bad entry point)"
[16:47:14] Script[gamemodes/Table.amx]: Run time error 20: "Invalid index parameter (bad entry point)"
[16:47:14] Number of vehicle models: 0
[16:47:14] New version of CrashDetect is available for download (4.13)
[16:47:17] [connection] 127.0.0.1:52630 requests connection cookie.
[16:47:18] [connection] incoming connection: 127.0.0.1:52630 id: 0
[16:47:19] [join] Smithson has joined the server (0:127.0.0.1)
[16:47:33] Player 0 selected object 1
[16:47:34] [debug] Run time error 4: "Array index out of bounds"
[16:47:34] [debug]  Accessing element at index 108 past array upper bound 9
[16:47:34] [debug] AMX backtrace:
[16:47:34] [debug] #0 0001a284 in public Streamer_OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3fb70000, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:34] [debug] #1 00019b24 in public OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3fb70000, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:35] [debug] Run time error 4: "Array index out of bounds"
[16:47:35] [debug]  Accessing element at index 108 past array upper bound 9
[16:47:35] [debug] AMX backtrace:
[16:47:35] [debug] #0 0001a284 in public Streamer_OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f1ea3d8, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:35] [debug] #1 00019b24 in public OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f1ea3d8, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:35] [debug] Run time error 4: "Array index out of bounds"
[16:47:35] [debug]  Accessing element at index 108 past array upper bound 9
[16:47:35] [debug] AMX backtrace:
[16:47:35] [debug] #0 0001a284 in public Streamer_OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f82851f, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:35] [debug] #1 00019b24 in public OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f82851f, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:35] [debug] Run time error 4: "Array index out of bounds"
[16:47:35] [debug]  Accessing element at index 108 past array upper bound 9
[16:47:35] [debug] AMX backtrace:
[16:47:35] [debug] #0 0001a284 in public Streamer_OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f598520, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:35] [debug] #1 00019b24 in public OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f598520, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:36] [debug] Run time error 4: "Array index out of bounds"
[16:47:36] [debug]  Accessing element at index 108 past array upper bound 9
[16:47:36] [debug] AMX backtrace:
[16:47:36] [debug] #0 0001a284 in public Streamer_OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x43072df4, 0xc291eeb4, 0x3f5c147c, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:36] [debug] #1 00019b24 in public OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000001, 0x43072df4, 0xc291eeb4, 0x3f5c147c, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
And the function doesn't display message when I clicked "save" button thanks for help in advance
Reply
#2

Where and how does "tableid" get assigned? I also want to point out the redundancy of the temporary coord variables. Just fetch the coordinates into the array directly.
Reply
#3

Hey, your answer is appriciated, here is the thing you asked for.

Code:
#define MAX_TABLES	10
Code:
enum TableInfo
{
	TableID, // this is how I'm trying to assign tableid which will be used futher on in saving.
	ObjectID,
	Text3D:Tableid,
	Float:X,
	Float:Y,
	Float:Z,
	Float:RX,
	Float:RY,
	Float:RZ,
code I'm using to avoid "undefined tableid" error:
Code:
new tableid = Table[tableid][TableID];
And didn't really understand last part you're trying to shove in my head is there a way to make it a little bit more simple? :P or to show example.

Thanks in advance
Reply
#4

This is such a basic problem really that with a bit of practice can be solved very easily every time. The biggest problem you have is the table creation function looks like a pretty shitty way to do it to me and that will cause issues with your whole system in the long run.

I always do it the same way every time when creating any kind of system like this for example. http://forum.sa-mp.com/showpost.php?...5&postcount=10
Reply
#5

Thank you, will try to follow to your guide repped, if I will encounter any problems I will post it here
Reply
#6

Okay so I changed my script a bit so I won't get confused that much, I added stuff you mentioned in link you provided, this is how my code looks like right now:

Code:
#define MAX_POKERTABLES			10
#define POKER_TABLE_OBJECT    	19474
#define POKER_TABLE_DIST     	150.0

#define DIALOG_CREATEPOKER				5000

#define TableBounds(%0,%1); \
	if(%0 < 0 || %0 > MAX_POKERTABLES) \
	{ \
		print(%1); \
	    return 0; \
	}
Code:
enum PokerInfo
{
	TableID,
	ObjectID,
	Float:PokerX,
	Float:PokerY,
	Float:PokerZ,
	Float:PokerRX,
	Float:PokerRY,
	Float:PokerRZ,
// stuff below
OnGameModeInit / Exit
Code:
public OnGameModeInit()
{
	for(new i = 0; i < MAX_POKERTABLES; i++)
	{
	    PokerTable[i][ObjectID] = INVALID_OBJECT_ID;
	}
	return 1;
}

public OnGameModeExit()
{
	for(new i = 0; i < MAX_POKERTABLES; i++)
	{
	    if(PokerTable[i][ObjectID] != INVALID_OBJECT_ID) DestroyObject(PokerTable[i][ObjectID]);
	}
	return 1;
}
Creating the Table - via dialogs

Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new Float:x, Float:y, Float:z;
	GetPlayerPos(playerid, x, y, z);
    if(dialogid == DIALOG_CREATEPOKER)
    {
        if(response)
        {
            if(CreatePokerTable(x, y, z) == -1) return SendClientMessage(playerid, 0xFF0000FF, "There are too many tables");
            SendClientMessage(playerid, -1, "New table created use /edittable to place it at desired location!!");
        }
        else
        {
            SendClientMessage(playerid, -1, "You canceled the poker creating menu!");
        }
        return 1;
    }

    return 0;
}
stock
Code:
stock CreatePokerTable(Float:x, Float:y, Float:z)
{
    for(new i = 0; i < MAX_POKERTABLES; i++)
    {
        if(PokerTable[i][ObjectID] != INVALID_OBJECT_ID) continue;
        
        PokerTable[i][ObjectID] = CreateObject(POKER_TABLE_OBJECT, x, y, z, 0.0, 0.0, 0.0, POKER_TABLE_DIST);
        PokerTable[i][PokerX] = Float:x;
		PokerTable[i][PokerY] = Float:y;
		PokerTable[i][PokerZ] = Float:z;
		return PokerTable[i][ObjectID];
	}
	print("ERROR: Tried to add too many hearts");
	return INVALID_OBJECT_ID;
}
but what the current problem is.. I can't really solve those "errors" I'm getting:
Code:
[16:47:34] [debug]  Accessing element at index 108 past array upper bound 9
[16:47:34] [debug] AMX backtrace:
[16:47:34] [debug] #0 0001a284 in public Streamer_OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3fb70000, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:34] [debug] #1 00019b24 in public OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3fb70000, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:35] [debug] Run time error 4: "Array index out of bounds"
[16:47:35] [debug]  Accessing element at index 108 past array upper bound 9
[16:47:35] [debug] AMX backtrace:
[16:47:35] [debug] #0 0001a284 in public Streamer_OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f1ea3d8, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:35] [debug] #1 00019b24 in public OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f1ea3d8, 0x00000000, 0x00000000, 0x00000000) from Poker.amx
[16:47:35] [debug] Run time error 4: "Array index out of bounds"
[16:47:35] [debug]  Accessing element at index 108 past array upper bound 9
[16:47:35] [debug] AMX backtrace:
Errors pops out whenever I'm editing the object with "SelectObject" function aka everytime I use the UI that SelectObject provides:
This is my OnPlayerEditObject callback I believe mistakes are in here:

Code:
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
    new tableid = PokerTable[tableid][TableID];
    new testmsg[600];
	new Float:oldX, Float:oldY, Float:oldZ, Float:oldRotX, Float:oldRotY, Float:oldRotZ;
	GetObjectPos(objectid, oldX, oldY, oldZ);
	GetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
	
	if(!playerobject) // If this is a global object, sync the position for other players // global = 0 | player = 1
	{
	    if(!IsValidObject(objectid)) return 1;
	    SetObjectPos(objectid, fX, fY, fZ);
     	SetObjectRot(objectid, fRotX, fRotY, fRotZ);
	}

	if(response == EDIT_RESPONSE_FINAL)
	{
	    new Float:x, Float:y, Float:z;
		GetObjectPos(objectid, x, y, z);
		PokerTable[tableid][PokerX] = Float:x;
		PokerTable[tableid][PokerY] = Float:y;
		PokerTable[tableid][PokerZ] = Float:z;
		
		new Float:RotX,Float:RotY,Float:RotZ;
		GetObjectRot(objectid, RotX, RotY, RotZ);
		PokerTable[tableid][PokerRX] = Float:RotX;
		PokerTable[tableid][PokerRY] = Float:RotY;
		PokerTable[tableid][PokerRZ] = Float:RotZ;
		format(testmsg,sizeof(testmsg),"Table is set at X: %f | Y: %f | Z: %f | RX: %f | RY: %f | RZ: %f",x,y,z,RotX,RotY,RotZ);
		SendClientMessage(playerid,-1, testmsg);
		// The player clicked on the save icon
		// Do anything here to save the updated object position (and rotation)
		
	}

	if(response == EDIT_RESPONSE_CANCEL)
	{
		//The player cancelled, so put the object back to it's old position
		if(!playerobject) //Object is not a playerobject
		{
			SetObjectPos(objectid, oldX, oldY, oldZ);
			SetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
		}
		else
		{
			SetPlayerObjectPos(playerid, objectid, oldX, oldY, oldZ);
			SetPlayerObjectRot(playerid, objectid, oldRotX, oldRotY, oldRotZ);
		}
	}
	return 1;
}
Biggest part is from wiki as I'm using this callback from samp wiki, so can you point me at right direction how to get rid of errors ? :/ what I'm trying to do is, when I place the table at desired location it should message me it's current coordinats x y z etc.
Reply
#7

return PokerTable[i][ObjectID]; should be the index of the poker table which is the variable "i". Think of the poker table as it's own entity an entity can contain many elements and elements of different types (objects, 3d text, textdraw etc) that are used in the system you are creating. Therefore you reference the array index ---PokerTable[ARRAY INDEX]--- of the given entity then reference it's elements of composition through the use of an enum ---PokerTable[ARRAY INDEX][ObjectID]---.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)