Raised This Month: $ Target: $400
 0% 

Enums & passing an element as a parameter


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ici
Member
Join Date: Jan 2014
Old 03-15-2016 , 09:42   Enums & passing an element as a parameter
Reply With Quote #1

Hey there fellas,

I have a nested enum data structure and I am trying to alter values by passing an element of the enum as a parameter.

Look at the "set" function and the commented line below so that you get an idea of what exactly I'm trying to achieve.

PHP Code:
#include <sourcemod>

enum Info
{
    
Info1,
    
Info2
}

enum DataType
{
    
Type1[Info],
    
Type2[Info]
}

enum Struct
{
    
Data[DataType]
}

new 
g_Data[MAXPLAYERS+1][Struct];

public 
OnPluginStart()
{
    
RegConsoleCmd("sm_teststruct"SM_Test);
}

public 
OnClientPutInServer(client)
{
    
g_Data[client][Data][Type1][Info1] = 0;
}

public 
Action:SM_Test(clientargs)
{
    
// set(client, DataType:Type1);
    
return Plugin_Handled;
}

set(clientDataType:param)
{
    
g_Data[client][Data][param][Info1] = 10;
    
g_Data[client][Data][param][Info2] = 20;

The problem is that it doesn't work and I'm trying to find a solution.
DataType:Type1 itself is an "array". Is there a way to tell the function which element/block of the DataType enum I want to modify?

I've tried adding brackets / untagging the param:
"error 028: invalid subscript (not an array or too many subscripts): "Type1""
"warning 215: expression has no effect"
"error 001: expected token: ";", but found: "]""
"error 029: invalid expression, assumed zero"

I'd be grateful if somebody can explain to me why this is not working. Also, I don't mind any dirty math solutions. I just want this concept to work.
ici is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 03-15-2016 , 18:36   Re: Enums & passing an element as a parameter
Reply With Quote #2

What about using this.

Code:
Dynamic data = Dynamic ();
data.SetInt("Info1", 10);
data.SetFloat ("Info2", 20.0);
__________________
Neuro Toxin 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 09:40.


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