Raised This Month: $ Target: $400
 0% 

add variable to float


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Boonie
Member
Join Date: Aug 2015
Old 04-18-2017 , 07:07   add variable to float
Reply With Quote #1

Edit: Oops, move to Scripting.

Is there a way to mix floats with variables? I keep getting a "must be a constant expression" error.

Example:
Code:
float stuff[3] =  { 48.0, 48.0, 40.0 };
float moreStuff[3] =  { 8.0, 4.0, 1.0 };

SetEntPropVector(i, Prop_Send, "m_vecMins", { stuff[0], moreStuff[1], stuff[2] } );
I know I can do it like this, but it doubles my code size.

Code:
float stuff[3] =  { 48.0, 48.0, 40.0 };
float moreStuff[3] =  { 8.0, 4.0, 1.0 };

float com[3];
com[0] = stuff[0];
com[1] = moreStuff[1];
com[2] = stuff[2]);

SetEntPropVector(i, Prop_Send, "m_vecMins", com);

Last edited by Boonie; 04-18-2017 at 09:53.
Boonie is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-18-2017 , 07:09   Re: add variable to float
Reply With Quote #2

It's because the { } array literal notation has to contain constant values. Never liked that myself either, but it looks like you'll have to go with your second code.

Last edited by klippy; 04-18-2017 at 07:09.
klippy is offline
Boonie
Member
Join Date: Aug 2015
Old 04-18-2017 , 07:11   Re: add variable to float
Reply With Quote #3

Well that's disappointing, thanks.
Boonie 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 06:57.


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