SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 09/12/2019, 06:11 PM   #1
NoteND
Huge Clucker
 
Join Date: May 2016
Posts: 214
Reputation: 3
Default 3 Dimensional arrays with enum

Hey!

Let me show you a code and then explain the problem or what I'm trying to do..

Code:
#define LOCATION1 1
#define LOCATION2 2
#define LOCATION3 3
#define LOCATION4 4

#define MAX_DYNAMIC_OBJECTS 500

enum ObjectData
{
	ObjectID
	...
}

new ObjectInfo[5][MAX_DYNAMIC_OBJECTS][ObjectData]

ObjectInfo[LOCATION1][0][ObjectID] = CreateDynamicObject...
I hope you get the idea of what I'm trying to do, but let me explain it otherwise.. is it possible to use 3dimensional array like that.. in first [] using define from "LOCATIONS" in second [] using number of MAX_DYNAMIC_OBJECT and in 3rd one we use name of actual enum..

How to make this work ?

Or will I have to do it like ObjectInfoLocation1[MAX_DYNAMIC_OBJECTS][ObjectData] for example..

NOTE: THATS JUST EXAMPLE, NOT MY ACTUAL CODE.
NoteND is online now   Reply With Quote
Old 09/12/2019, 06:55 PM   #2
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,899
Reputation: 1321
Default Re: 3 Dimensional arrays with enum

You are overthinking your problem you have created an extra dimension in your array for absolutely no good reason. Instead move it to your enum like this.

Code:
#define MAX_DYNAMIC_OBJECTS 500
#define MAX_LOCATIONS 5

enum ObjectData
{
	ObjectID,
        LocationID,
	...
}

new ObjectInfo[MAX_DYNAMIC_OBJECTS*MAX_LOCATIONS][ObjectData]

ObjectInfo[index][ObjectID] = CreateDynamicObject()
ObjectInfo[index]LocationID] = SomeLocationId;
Pottus is offline   Reply With Quote
Old 09/12/2019, 07:10 PM   #3
NoteND
Huge Clucker
 
Join Date: May 2016
Posts: 214
Reputation: 3
Default Re: 3 Dimensional arrays with enum

Quote:
Originally Posted by Pottus View Post
You are overthinking your problem you have created an extra dimension in your array for absolutely no good reason. Instead move it to your enum like this.

Code:
#define MAX_DYNAMIC_OBJECTS 500
#define MAX_LOCATIONS 5

enum ObjectData
{
	ObjectID,
        LocationID,
	...
}

new ObjectInfo[MAX_DYNAMIC_OBJECTS*MAX_LOCATIONS][ObjectData]

ObjectInfo[index][ObjectID] = CreateDynamicObject()
ObjectInfo[index]LocationID] = SomeLocationId;

Maybe I didnt give best example.. because what you wrote will never work in my actual case
NoteND is online now   Reply With Quote
Old 09/12/2019, 11:34 PM   #4
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,899
Reputation: 1321
Default Re: 3 Dimensional arrays with enum

What do you mean it won't work? I can see how you are trying to do and you are doing it incorrectly or if you need to do it this way your method needs serious improvements elsewhere.
Pottus is offline   Reply With Quote
Old 10/12/2019, 12:56 PM   #5
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,167
Reputation: 73
Default Re: 3 Dimensional arrays with enum

Well, it'll be better if you follow Pottus's suggestion.
but I assume, you want to use your defined numbers, I suggest to write something like that:
PHP Code:
enum //locations
{
    
LOCATION1,
    
LOCATION2,
    
LOCATION3
}

if(
ObjectInfo[index][LocationID] == LOCATION1) ... 
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi-Dimensional Arrays venomlivno8 Scripting Help 7 30/07/2014 04:34 PM
2-dimensional textdraw arrays Whizion Scripting Help 9 29/10/2013 07:37 PM
[HELP] Multi dimensional arrays ReDevilGames Scripting Help 3 14/02/2013 08:40 PM
[Tutorial] 2-dimensional arrays in enum MadeMan Tutorials 1 29/08/2012 12:08 PM
multi-dimensional arrays >? Kar Help Archive 3 02/08/2010 09:26 AM


All times are GMT. The time now is 05:25 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.