Raised This Month: $ Target: $400
 0% 

Take the sum of a variable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragos
Senior Member
Join Date: Oct 2018
Location: Romania
Old 12-26-2020 , 10:28   Take the sum of a variable
Reply With Quote #1

Hello,

I want to ask how to take the value of a variable, example:
PHP Code:
new SUM1 
and get the value it to a new public function
PHP Code:
 public takesum () new TAKESUM1 = ?? 
__________________
sup
Dragos is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 12-26-2020 , 11:07   Re: Take the sum of a variable
Reply With Quote #2

One of the easiest ways is to create the variable globally, so it is accessible in any function.
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
Dragos
Senior Member
Join Date: Oct 2018
Location: Romania
Old 12-26-2020 , 11:47   Re: Take the sum of a variable
Reply With Quote #3

What do you mean?
Can you show a example?
__________________
sup

Last edited by Dragos; 12-26-2020 at 11:54.
Dragos is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 12-26-2020 , 12:41   Re: Take the sum of a variable
Reply With Quote #4

Quote:
Originally Posted by Dragos View Post
What do you mean?
Can you show a example?
You asked a question in the "scripting help" area, keep in mind that if you don't know how to code you should post in the "suggestions / request" area.

PHP Code:
/* Sublime AMXX Editor v4.2 */

#include <amxmodx>
// #include <amxmisc>
// #include <cstrike>
// #include <engine>
// #include <fakemeta>
// #include <hamsandwich>
// #include <fun>
// #include <xs>
// #include <sqlx>

#define PLUGIN  "New Plug-In"
#define VERSION "1.0.0-8"
#define AUTHOR  "Author"

new GlobalVariable[32]
new 
GlobalVariable2

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /test""Func")
}

public 
FirstFunc()
{
    switch(
random_num(02))
    {
        case 
0
        {
            
formatex(GlobalVariablecharsmax(GlobalVariable), "Hello World")
            
GlobalVariable2 0
        
}
        case 
1
        {
            
formatex(GlobalVariablecharsmax(GlobalVariable), "Hey wazzup")
            
GlobalVariable2 1
        
}
        case 
2
        {
            
formatex(GlobalVariablecharsmax(GlobalVariable), "BZZZ ERROR")
            
GlobalVariable2 2
        
}
    }
}

public 
Func(id)
{
    
FirstFunc()
    
client_print(id3"VariableString = %s | VariableInt = %i"GlobalVariableGlobalVariable2)
    return 
PLUGIN_HANDLED

__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
Dragos
Senior Member
Join Date: Oct 2018
Location: Romania
Old 12-27-2020 , 09:36   Re: Take the sum of a variable
Reply With Quote #5

Ideea it's that my variable it's like this:


PHP Code:
public something (id) {
new 
test random_num(0,16)
}

public 
form (id) {
    new 
COREs test

I want to do like this. But it give some errors
__________________
sup

Last edited by Dragos; 12-27-2020 at 09:40.
Dragos is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-27-2020 , 10:51   Re: Take the sum of a variable
Reply With Quote #6

Quote:
Originally Posted by Dragos View Post
Ideea it's that my variable it's like this:


PHP Code:
public something (id) {
new 
test random_num(0,16)
}

public 
form (id) {
    new 
COREs test

I want to do like this. But it give some errors
This is because when you declare a variable within a function (local variable), it can only be used within that function. You will need to do what iceeedr suggested and declare it globally--outside of a function, towards the top under your #include's, (global variable), which allows any function in your plugin to access the value. Keep in mind that if one function changes it, it gets changed everywhere the variable is used across your plugin.

This is 'hello world' level stuff, I would do some more learning because you are going to have issues left and right until you understand the basic concepts.

Code:
//Declare variable globally new test public something (id) {     //Remove local declaration of variable     //new test = random_num(0,16)     //Instead you will use (instead of create) the variable that was declared globally     test = random_num(0,16) } public form (id) {     //This should now work     new COREs = test }

If you do not need the variable to be accessed by the entire plugin, you can instead declare it locally and pass it to another function so it can be used.
PHP Code:
public somethingid 
{
    new 
test random_num16 )
    
formid test )
}

public 
formid SomeValue 
{
    
//COREs will be assigned the 'test' value from function something()
    
new COREs SomeValue 

__________________

Last edited by Bugsy; 12-27-2020 at 23:31.
Bugsy is offline
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

Forum Jump


All times are GMT -4. The time now is 14:06.


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