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

Programming for starters


Post New Thread Reply   
 
Thread Tools Display Modes
makavelli
Senior Member
Join Date: Nov 2006
Location: Belgium
Old 01-17-2012 , 08:53   Re: Programming for starters
Reply With Quote #91

Quote:
Originally Posted by fysiks View Post
Just about everything is listed here.
nice tyvm
makavelli is offline
MrMaCEEE
Senior Member
Join Date: Apr 2010
Location: PortugaL
Old 01-12-2013 , 22:30   Re: Programming for starters
Reply With Quote #92

Joaquim também era bom fazeres esse tutorial em Portugues, tornava-se um bocadinho mais bem explicado para todos os tugas ;) Ja agora era porreiro se ensinasses a transformar um plugins a gravar os dados em NVault para MySQL, já ando a bastante tempo a tentar fazer isso mas não sei como. Abraço
__________________

#include ++ by MACE

Last edited by YamiKaitou; 01-14-2013 at 20:13. Reason: removed quoted message
MrMaCEEE is offline
Send a message via MSN to MrMaCEEE
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-13-2013 , 01:55   Re: Programming for starters
Reply With Quote #93

Quote:
Originally Posted by MrMaCEEE View Post
Joaquim também era bom fazeres esse tutorial em Portugues, tornava-se um bocadinho mais bem explicado para todos os tugas ;) Ja agora era porreiro se ensinasses a transformar um plugins a gravar os dados em NVault para MySQL, já ando a bastante tempo a tentar fazer isso mas não sei como. Abraço
This is an english forum. If you want to talk other languages, post in the Multilingual section.
__________________
fysiks is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 01-13-2013 , 11:24   Re: Programming for starters
Reply With Quote #94

Quote:
Originally Posted by MrMaCEEE View Post
Ja agora era porreiro se ensinasses a transformar um plugins a gravar os dados em NVault para MySQL, já ando a bastante tempo a tentar fazer isso mas não sei como. Abraço
You need to loop through all nVault entries and then send the keys / data to the database.
http://forums.alliedmods.net/showthread.php?t=139584
Post in the Suggestions / Requests or Scripting Help if you have doubts.

Last edited by guipatinador; 01-13-2013 at 11:29.
guipatinador is offline
ServO
Senior Member
Join Date: Nov 2009
Location: Are you asking me out?
Old 01-14-2013 , 06:02   Re: Programming for starters
Reply With Quote #95

Helped alot, thanks!
__________________
Zombie Dominance

To Do:
- Learn AMXx Script...
ServO is offline
Old 08-20-2013, 12:37
LordOfNothing
This message has been deleted by ConnorMcLeod. Reason: troll, or posting random confusing code, or posting for posts count
JoKeR LauGh
Veteran Member
Join Date: May 2011
Location: Malaysia
Old 01-01-2017 , 10:49   Re: Programming for starters
Reply With Quote #96

Hello, sorry for reviving.
I am totally new to coding and I have actually a couple of silly question..
In Part 1, in the

PHP Code:
changeColorLuminosity(anyColor[3],factor)
{
    
anyColor[0] = anyColor[0] + factor
    anyColor
[1] = anyColor[1] + factor
    anyColor
[2] = anyColor[2] + factor
    
    
if(anyColor[0] < 0)
    {
        
anyColor[0] = 0
    
}
    
    if(
anyColor[1] < 0)
    {
        
anyColor[1] = 0
    
}
        
    if(
anyColor[2] < 0)
    {
        
anyColor[2] = 0    
    
}

In the function, the factor. Should it be declared as a global variable before that?
and.. isn't
PHP Code:
changeColorLuminosity(anyColor[3]) 
is enough?
Thank you in advance. Sorry for asking a simple question..
__________________
Quote:
Originally Posted by addons_zz View Post
Also, just to not read `the article`, read all you find. Read and read, for ever and ever. Never stop reading.
Why? Because there is not one single universal truth which holds the meaning for everything.

Last edited by JoKeR LauGh; 01-01-2017 at 10:51.
JoKeR LauGh is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-01-2017 , 11:00   Re: Programming for starters
Reply With Quote #97

"factor" is a formal parameter in that function, it does not have to be declared again. When you call that function you supply a value, which is called the actual parameter. This one may be declared. What I mean is:
PHP Code:
changeColorLuminosity(anyColor[3],factor//here you have formal params
{
    
anyColor[0] = anyColor[0] + factor
    anyColor
[1] = anyColor[1] + factor
    anyColor
[2] = anyColor[2] + factor
    
    
if(anyColor[0] < 0)
    {
        
anyColor[0] = 0
    
}
    
    if(
anyColor[1] < 0)
    {
        
anyColor[1] = 0
    
}
        
    if(
anyColor[2] < 0)
    {
        
anyColor[2] = 0    
    
}
}  

public 
some_function()
{
     new 
anyColor[3], factor 4
     changeColorLuminosity
(anyColorfactor// actual param, the variable "factor" is declared above. It can be global, if you need to use it in multiple functions. You could just do changeColorLuminosity(anyColor, 4), but it really depends on the plugin you are writting.

For the second question, it isn't enough for your function, because it has two formal params, so you need to provide two actual params.
I've tried to explain this as simple as I could.
__________________

Last edited by HamletEagle; 01-01-2017 at 11:01.
HamletEagle is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-01-2017 , 18:42   Re: Programming for starters
Reply With Quote #98

Quote:
Originally Posted by JoKeR LauGh View Post
In the function, the factor. Should it be declared as a global variable before that?
PHP Code:
changeColorLuminosity(anyColor[3]) 
Yes. If you do not pass the factor parameter and you function signature ìs `changeColorLuminosity(anyColor[3])`, you need to declare the `factor` as a global variable before the function declaration.


Example: (correct)


PHP Code:
new factor // everything ok

changeColorLuminosity(anyColor[3])
{
    
anyColor[0] = anyColor[0] + factor
    
....

Example: (incorrect)
PHP Code:
changeColorLuminosity(anyColor[3])
{
    
anyColor[0] = anyColor[0] + factor
    
....
}

new 
factor // variable not declared error 
However this is not true for functions declarations. This both cases are valid in AMXX pawn.

Example: (correct)
PHP Code:
func1(anyColor[3],factor)
{
    
anyColor[0] = anyColor[0] + factor
    
....
}

func2(anyColor[3],factor)
{
    
func1(anyColor,factor)
    ....

Example: (also correct)
PHP Code:
func2(anyColor[3])
{
    
func1(anyColor,factor)
    ....
}

func1(anyColor[3])
{
    
anyColor[0] = anyColor[0] + factor
    
....

__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-01-2017 , 22:37   Re: Programming for starters
Reply With Quote #99

Quote:
Originally Posted by addons_zz View Post
Yes. If you do not pass the factor parameter and you function signature ìs `changeColorLuminosity(anyColor[3])`, you need to declare the `factor` as a global variable before the function declaration.
Using a global variable is bad advice (because it prevents proper modularity). Leave it as a parameter of the function. What HamletEagle said is better.

If "JoKeR LauGh" wants to not provide the 'factor' parameter then a default value should be defined for that function.
__________________
fysiks is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-01-2017 , 23:17   Re: Programming for starters
Reply With Quote #100

I am not advising he to use global, I am just answering something which looked like a question about syntax.
He should use global when he needs the data be preserved across the whole plugin life.

If the variable `factor` does not need to hold such life cycle, he should not declare it as a global,
as he would just unnecessarily be increasing his code maintenance complexity unnecessarily.
Though, if he only need the factor to be alive on that function explicitly he can declare it locally as static.

If he want to know more search as https://www.google.com/search?q=why+globals+are+bad.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 01-01-2017 at 23:29. Reason: misspelling
addons_zz 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 01:55.


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