Raised This Month: $51 Target: $400
 12% 

How does one store vectors in an `any` array?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 06-23-2017 , 10:46   How does one store vectors in an `any` array?
Reply With Quote #1

For example:
Code:
enum
{
	vector_x,
	vector_y,
	vector_z,
	SETTINGS_SIZE
};

any[] mysettings = new any[SETTINGS_SIZE];

mysettings[vector_x] = -45.0;
mysettings[vector_y] = 0.0;
mysettings[vector_z] = 360.0;
This works perfectly fine, but - is there anything I can do to make it cleaner? Like so:

Code:
#include <sourcemod>

enum
{
	vector[3],
	SETTINGS_SIZE
};

any[] mysettings = new any[SETTINGS_SIZE];

float myvector[3];
myvector[0] = 0.0;
myvector[1] = 0.0;
myvector[2] = 0.0;

mysettings[vector] = myvector;
Which unfortunately doesn't compile.. and the compiler throws this error for the last line:

Code:
error 006: must be assigned to an array
Thanks.
__________________
retired
shavit is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 06-23-2017 , 11:45   Re: How does one store vectors in an `any` array?
Reply With Quote #2

Don't think you can user arrays in enum, but always possible to just loop or make your own VectorCopy function to make it cleaner
hmmmmm is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 06-23-2017 , 11:49   Re: How does one store vectors in an `any` array?
Reply With Quote #3

You'd just be making your code more complicated if you use enums to store data in arrays.
Just make separate arrays for each section of data you want to store.
Mitchell is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 06-23-2017 , 11:49   Re: How does one store vectors in an `any` array?
Reply With Quote #4

Quote:
Originally Posted by hmmmmm View Post
Don't think you can user arrays in enum, but always possible to just loop or make your own VectorCopy function to make it cleaner
Fair enough, I'll create my own 'vector copy' function.

To anyone else: let me know if there's a real solution and not a workaround, then I'll set the thread to solved if there is .

Quote:
Originally Posted by Mitchell View Post
You'd just be making your code more complicated if you use enums to store data in arrays.
Just make separate arrays for each section of data you want to store.
I wish that was the case.. but it isn't. Having separate arrays just make the whole thing extremely messy in my code.
__________________
retired

Last edited by shavit; 06-23-2017 at 11:50.
shavit is offline
Kryptanyte
Junior Member
Join Date: Dec 2015
Old 06-24-2017 , 10:43   Re: How does one store vectors in an `any` array?
Reply With Quote #5

I don't know if this will still work with an any array but it works with int arrays

PHP Code:
enum Vector_Struct
{
    
Float:vector[3],
    
SETTINGS_SIZE
}

int MyVector[Vector_Struct];

float NewVector[3];
NewVector[0] = 0.0;
NewVector[1] = 0.0;
NewVector[2] = 0.0;

MyVector[vector] = NewVector
It's possible that MyVector[vector] = NewVector; may not work properly and might need a copy function to work properly.
Kryptanyte is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 00:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode