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

Variables can be declared in multiple ways, but what's the difference?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
gromit190
Junior Member
Join Date: Jun 2019
Old 06-11-2019 , 07:59   Variables can be declared in multiple ways, but what's the difference?
Reply With Quote #1

Hi,


I'm a little bit confused about how a variable is declared and instantiated.

From what I understand, variables can be declared in 3 different ways (example using a StringMap variable):

1. new Float:myFloat
2. decl Float:myFloat
3. Float myFloat

All 3 methods declare a new variable named "myFloat".
Method 1 declares and instantiates myFloat, meaning that there is no previous data in this variable (data is set to 0, for other types everything would be 0, false etc).
Method 2 declares myFloat, but there may be "leftover" data. So depending on what is previously in computer memory, there may be some data in the variable. This can only be done in a local scope (inside a function).
Method 3 ???

The difference between method 1 and 2 are okay I guess, but what's the difference between method 1 and 3?
Is the data set to 0 when using method 3?
If I want a global variable in my plugin, should I use method 1 or 3?


Code:
#include <sourcemod>

Float myGlobalVariable;

public void OnPluginStart()
{
    myGlobalVariable = 0.0;
}

Last edited by gromit190; 06-11-2019 at 07:59.
gromit190 is offline
 



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 16:40.


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