SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 23/08/2017, 12:15 AM   #4341
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,449
Reputation: 515
Default Re: Little coding questions - For general minor queries 5

No different than using "Sonmthing_Func", just a macro. Sometimes used for emphasis that it is a namespace. For example I started using something like "Player.Meta[playerid][name]" which is preprocessed to "Player.Meta[playerid][E_PLAYER_Meta_name]", so better check definition of the replacement macro to be sure it doesn't do something more behind the scenes.
Misiur is offline   Reply With Quote
Old 23/08/2017, 02:17 AM   #4342
Dignity
High-roller
 
Dignity's Avatar
 
Join Date: May 2013
Location: Belgium
Posts: 1,770
Reputation: 1037
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Misiur View Post
No different than using "Sonmthing_Func", just a macro. Sometimes used for emphasis that it is a namespace. For example I started using something like "Player.Meta[playerid][name]" which is preprocessed to "Player.Meta[playerid][E_PLAYER_Meta_name]", so better check definition of the replacement macro to be sure it doesn't do something more behind the scenes.
So in essence it actually doesn't benefit anything other than minor personal organization.

Alright, fair enough.
__________________


Shoot me or Reyo a PM for more information.
Dignity is offline   Reply With Quote
Old 23/08/2017, 02:46 AM   #4343
Paulice
Gangsta
 
Join Date: Jul 2017
Posts: 497
Reputation: 44
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Dignity View Post
So in essence it actually doesn't benefit anything other than minor personal organization.

Alright, fair enough.
To prevent "symbol already defined" and so forth.
Paulice is offline   Reply With Quote
Old 28/08/2017, 11:52 AM   #4344
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 61
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

Is it possible to reffer to a column by id and not by name? Like how you can extract data from a 'SELECT' both with db_get_field (by a number) and db_get_field_assoc (by name).

Let's say I have this db for example:
PHP Code:
ID name Money 
and instead of saving like this
PHP Code:
UPDATE table SET money='5' WHERE id='1' 
I want this
PHP Code:
UPDATE table SET SOME_KIND_OF_STATEMENT_TO_REFFER_TO_COLUMN_1='5' 
number instead of name
GaByM is offline   Reply With Quote
Old 28/08/2017, 12:05 PM   #4345
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,717
Reputation: 1255
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Paulice View Post
To prevent "symbol already defined" and so forth.
static is good for that.

Quote:
Originally Posted by GaByM View Post
Is it possible to reffer to a column by id and not by name? Like how you can extract data from a 'SELECT' both with db_get_field (by a number) and db_get_field_assoc (by name).

Let's say I have this db for example:
PHP Code:
ID name Money 
and instead of saving like this
PHP Code:
UPDATE table SET money='5' WHERE id='1' 
I want this
PHP Code:
UPDATE table SET SOME_KIND_OF_STATEMENT_TO_REFFER_TO_COLUMN_1='5' 
number instead of name
Probably not, the db_get_field is just a helper but it's best to always use names tbh because if you add a new column, you won't run into any issues later on.
[HLF]Southclaw is offline   Reply With Quote
Old 28/08/2017, 05:22 PM   #4346
10MIN
Huge Clucker
 
10MIN's Avatar
 
Join Date: Jun 2017
Location: Clockania
Posts: 298
Reputation: 27
Default Re: Little coding questions - For general minor queries 5

What do you think is more "better" for a ban system:
  • Using 2 mysql collumns: one for storing integer format of timestamp and another for storing the timestamp in a date and time format
  • Using one mysql collumn for storing the timestamp and using a include to transform it to time and date.

I am just "confused" and don't know which method is "better".
__________________
__________________
__________________
__________________
__________________
__________________
__________________
10MIN is offline   Reply With Quote
Old 28/08/2017, 05:37 PM   #4347
Misiur
High-roller
 
Misiur's Avatar
 
Join Date: Jul 2009
Location: Poland
Posts: 2,449
Reputation: 515
Default Re: Little coding questions - For general minor queries 5

You can convert your timestamps in your SQL query: see https://dev.mysql.com/doc/refman/5.5...functions.html
FROM_UNIXTIME and UNIX_TIMESTAMP
Misiur is offline   Reply With Quote
Old 30/08/2017, 02:57 AM   #4348
Arthur Kane
Gangsta
 
Join Date: Sep 2012
Location: Los Angeles
Posts: 683
Reputation: 93
Default Re: Little coding questions - For general minor queries 5

I'm having a problem:

Code:
for(new f = 0, t = 0; f < MAX_PLAYERS, t < 5; f++)
{
	if(!IsPlayerConnected(f))
		continue;
						
	if(strfind(ReturnName(f, 0), params, true) != -1)
	{
		matchesFound[t] = f;
		t++; 
	}
}
This continues to return INVALID_PLAYER_ID and I haven't got a single clue as to why.
Code:
[debug]  Attempted to read/write array element at index 65536 in array of size 50
The error originates from the strfind.

It calls INVALID_PLAYER_ID for ReturnName() and causes it to crash I assume.
Code:
[debug] #0 0005856c in ReturnName (playerid=65536, underScore=0) at macc.pwn:7239
Arthur Kane is online now   Reply With Quote
Old 30/08/2017, 03:19 AM   #4349
Paulice
Gangsta
 
Join Date: Jul 2017
Posts: 497
Reputation: 44
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Arthur Kane View Post
I'm having a problem:

Code:
for(new f = 0, t = 0; f < MAX_PLAYERS, t < 5; f++)
{
	if(!IsPlayerConnected(f))
		continue;
						
	if(strfind(ReturnName(f, 0), params, true) != -1)
	{
		matchesFound[t] = f;
		t++; 
	}
}
This continues to return INVALID_PLAYER_ID and I haven't got a single clue as to why.
Code:
[debug]  Attempted to read/write array element at index 65536 in array of size 50
The error originates from the strfind.

It calls INVALID_PLAYER_ID for ReturnName() and causes it to crash I assume.
Code:
[debug] #0 0005856c in ReturnName (playerid=65536, underScore=0) at macc.pwn:7239
Post ReturnName's code!
Paulice is offline   Reply With Quote
Old 30/08/2017, 03:22 AM   #4350
Arthur Kane
Gangsta
 
Join Date: Sep 2012
Location: Los Angeles
Posts: 683
Reputation: 93
Default Re: Little coding questions - For general minor queries 5

ReturnName isn't relevant. The loop is returning INVALID_PLAYER_ID and calling it with ReturnName.
Arthur Kane is online now   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make a soldier aotumaticly be general when the general dies ? AlbanianGuy Scripting Help 35 13/05/2012 04:35 PM
Minor problem Desert Help Archive 4 17/03/2010 07:24 PM
Counting with mysql queries actiwe Help Archive 2 26/02/2010 03:36 PM
SQL queries using GROUP BY Dabombber Help Archive 2 05/10/2009 08:47 PM


All times are GMT. The time now is 05:47 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.