Today I learned - Share your newly found knowledge!

No, you don't use this kind of switch for your fishing system, and it's stupid if you do it in this manner to me. This means that the code you've made is not efficient and friendly. I can be wrong but you should post more of your system and ask for suggestions in scripting help.
Reply

Quote:
Originally Posted by GaByM
Посмотреть сообщение
Yes, but I did this:

Код HTML:
#include <a_samp>


main()
{
	new b;
	switch(b)
	{
		case 0..20000: {}
		case 20001..115000: {}
		case 115001..200000: {}
		default: {}
	}
}
Which could be so nicely divided by 5000 or 10000, but who would have thought 3 lines of code can take so much to compile?
If you're going to check for ranges you should use "if, elseif, else" instead.
Reply

"case 0 .. 5:" is just shorthand for "case 0, 1, 2, 3, 4, 5:". So you are creating a switch statement with 200000 cases in, not just 3. That is why it is slow (not the only problem with your code btw). You compared it to "if (0 <= x <= 5)", but it is actually more like "if (x == 0 || x == 1 || x == 2 || x == 3 || x == 4 || x == 5)". You need to learn to use the right tool for the job, not go for the one that looks nicer then wonder why it isn't very good!
Reply

Quote:
Originally Posted by Logic_
Посмотреть сообщение
No, you don't use this kind of switch for your fishing system, and it's stupid if you do it in this manner to me. This means that the code you've made is not efficient and friendly. I can be wrong but you should post more of your system and ask for suggestions in scripting help.
Please do constructive criticism by posting a better way to do it instead of just saying that's a stupid way to do it.
Reply

Quote:
Originally Posted by admantis
Посмотреть сообщение
Please do constructive criticism by posting a better way to do it instead of just saying that's a stupid way to do it.
I just said about what I thought and had in my mind at that time. Y_Less gave the answer to his question and I've also helped the poster through PM as he requested. Not everything is done is public...
Reply

Today I Learned, if you have an file called "default.inc" in your include directory she is automatic included.
https://github.com/Southclaws/pawn/b...ler/sc1.c#L620
Reply

Quote:
Originally Posted by Dayvison_
Посмотреть сообщение
Today I Learned, if you have an file called "default.inc" in your include directory she is automatic included.
https://github.com/Southclaws/pawn/b...ler/sc1.c#L620
For a moment I got very excited by the prospects of this, but then after some playing I realised that it is not as useful as it might at first seem for one simple reason - it is included before "a_samp". Yes, you could include "a_samp" from inside it, but a common pattern is:

PHP код:
#include <a_samp>
#undef MAX_PLAYERS
#define MAX_PLAYERS 20
#include <other> 
If "default.inc" existed, and even if it included "a_samp" itself, all of its code would be parsed before the redefinition of "MAX_PLAYERS", so any code that relied on that value would be wrong. My first thought was for automatic inclusion of "fixes.inc", but that wouldn't work. Almost any non-trivial code that in any way dealt with the SA:MP API would be unable to be located in that file (and frankly that doesn't leave much - even "amx_assembly" includes "a_samp" (though I'm not entirely sure why)).
Reply

I'm getting 'tag mismatch' warning in this code...

PHP код:
PlayerTextDrawShow(playeridpCharCreateTD[playerid][CHAR_TEXTDRAW_AGE]); 
You would probably think why I'd do [CHAR_TEXTDRAW_AGE] instead of [6], so I'll tell you the reason before you even think of that. Readability.

How do I define CHAR_TEXTDRAW_AGE? Well, I've an enumerator in which I've defined it and other similar data. Simple, right?

And I've tried...
PHP код:
PlayerTextDrawShow(playerid_:pCharCreateTD[playerid][_:CHAR_TEXTDRAW_AGE]); 
PHP код:
PlayerTextDrawShow(playerid_:pCharCreateTD[playerid][CHAR_TEXTDRAW_AGE]); 
PHP код:
PlayerTextDrawShow(playeridpCharCreateTD[playerid][_:CHAR_TEXTDRAW_AGE]); 
nothing helped...

TILL

I used #define instead of defining it in an enumerator and my warnings went away.

---

If you do the same trick as above for something like...

PHP код:
enum
{
    
MAX_VALUE 1000,
    
MAX_TIME 5

and, use that value in SendClientMessage or another, for example,
PHP код:
SendClientMessage(playerid, -1"Stand in the red checkpoint for "MAX_TIME" inorder to access it"); 
. It'll send the message without the value, but if you define it, it'll send the message with MAX_TIME value!

---

So TIL multiple pros of #define and cons of using enumerator. And I'd like to know why or how this happen and more usage tips about them (define and enums).
Reply

Quote:
Originally Posted by Logic_
Посмотреть сообщение
...
I don't know how did you defined your enum and your pCharCreateTD array, but I think this should work:

PHP код:
PlayerTextDrawShow(playeridPlayerText:pCharCreateTD[playerid][CHAR_TEXTDRAW_AGE]); 
When you create an enum, every value in that enum is tagged with it's name, so PlayerTextDrawShow expects an PlayerText: tag but gets other tag (also note that PlayerText is a strong tag).

More info: https://sampforum.blast.hk/showthread.php?tid=318307 about enums
https://sampwiki.blast.hk/wiki/Scripting:tags about tags, strong tags etc
Reply

Quote:
Originally Posted by GaByM
Посмотреть сообщение
When you create an enum, every value in that enum is tagged with it's name, so PlayerTextDrawShow expects an PlayerText: tag but gets other tag (also note that PlayerText is a strong tag).

https://sampwiki.blast.hk/wiki/Scripting:tags about tags, strong tags etc
Holy cow! I forgot about strong and weak tags Thanks mane.
Reply

Destructors in PAWN

This is not documented in the PAWN Language Guide which is why this feature was unknown for quite a long time (11 years?). The implementer guide hints about destructors at few places though.

Declaration of destructors:
Код:
operator~(MyTag:arr[], size) { }
At the first glance, it feels like the destructor works only with arrays. However, this is not true. The above function signature is applicable to both arrays and variables.

The first parameter is essentially behaves as a reference variable in case of variables being destroyed and as a reference array in case of arrays. This means that you can know where the object was stored in memory. The tag of this parameter participates in overload resolution.

The second parameter provides the size of the first parameter. The tag of this parameter is ignored during overload resolution. By that, I mean to say that: if you have `new arr[tag1:10], arr2[tag2:20];", the same destructor will be called for both. In fact, you cannot create two destructors that differ only in the tag of the this parameter.

The destructor cannot have a return type. The compilation will fail if all the dimensions of an array (which has a destructor) is not explicitly given during declaration (even if all the sizes can be determined at compile-time).

Examples:
Код:
#include <a_samp>
operator~(Tag:arr[], size) {
	new address;
	#emit LOAD.S.pri arr
	#emit STOR.S.pri address
	printf("Destructor Called: address:%d, first-value:%d, size:%d", address, _:arr[0], size);
}

main ()
{
     new Tag:arr[] = {Tag:1, Tag:2, Tag:3};
     {
          new Tag:var;
     }
}
will result in:

Код:
Destructor Called: address:16584, first-value:0, size:1
Destructor Called: address:16588, first-value:1, size:3
Код:
#include <a_samp>
operator~(Tag:arr[], size) {
	new address;
	#emit LOAD.S.pri arr
	#emit STOR.S.pri address
	printf("Destructor Called: address:%d, first-value:%d, size:%d", address, _:arr[0], size);
}

func(&Tag:a, Tag:b = Tag:5) {
     return;
}
main ()
{
     new Tag:x = Tag:10;
     func(x);
     printf("end of main");
}
will give:

Код:
Destructor Called: address:16628, first-value:5, size:1
end of main
Destructor Called: address:16632, first-value:10, size:1
Multi-dimensional arrays
The destructor is not called for multi-dimensional arrays in the default PAWN compiler.

The Zeex compiler calls the destructor for the data of the array. The first parameter of the destructor will point to the start of the data of the array and the second parameter will provide the total number of elements in the array. The entire multi-dimensional array has to be accessed as if it were a single dimensional array.

[FIXES PENDING]

Order of destruction:
The destructors are called in the reverse order of declaration (most recently declared will be destroyed first).

Код:
new Tag:a = 2, Tag2:b = 5;
{
	   new Tag3:c;
}
"c" will be destroyed first, "b" will be destroyed next and "a" finally.

Notes:
  1. destructors are not called for global variables
  2. destructors are called for variables and arrays only (they are not called for references or array references)
Bugs:
  1. destructors are called for local static variables every time the function is called (it shouldn't be called at all given that destructors are not called for globals) Issue at Zeex's compiler Repo
  2. destructors are called for arguments only at explicit returns, i.e: destructors for arguments are not called unless you add a return statement at the end of the function
    Issue at Zeex's compiler Repo
  3. destructors are not called for multi-dimensional arrays in the default compiler and are called wrongly in the Zeex compiler
[PR for Zeex's Compiler aiming to resolve all of them]
Reply

Mt Grande deu atй Preguiзa de ler
Reply

here's what i learned today, don't base any of your scripts on a samp update until its out of RC.
Reply

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
here's what i learned today, don't base any of your scripts on a samp update until its out of RC.
real knowledge ( ͡° ͜ʖ ͡°)
Reply

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
here's what i learned today, don't base any of your scripts on a samp update until its out of RC.
so much knowledge, such a genius.
even Albert Einstein didn't think about this.
Reply

Quote:
Originally Posted by RogueDrifter
Посмотреть сообщение
here's what i learned today, don't base any of your scripts on a samp update until its out of RC.
Just make a branch, nerd-o.
Reply

Quote:
Originally Posted by Jeroen52
Посмотреть сообщение
Just make a branch, nerd-o.
Only few people here use versioning, and even less that use it the right way.
Reply

Quote:
Originally Posted by DRIFT_HUNTER
Посмотреть сообщение
Only few people here use versioning, and even less that use it the right way.
Looks like right now is the wrong moment to learn, however saying that it is right to learn it anytime.


For those wondering: DOWNLOAD GIT AND LEARN IT.
Reply

Today i learn'd
this - here code and logs....

Код:
if(mysql_errno(g_handle) != 0) // either connected or failed to connect
	{
		print("[MySQL] Failed the connection to \"phpMyAdmin\".\n");
		SendRconCommand("exit");
	}
	else
	{
	    print("[MySQL] Successfully made a connection to \"phpMyAdmin\".\n");
	}
using the latest MySQL version i was checking when the MySQL was connected or failed to make connection

R41-4

log when failed to connect to mysql phpmyadmin

Код HTML:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7-R2, ©2005-2015 SA-MP Team

[07:58:30] filterscripts = ""  (string)
[07:58:30] 
[07:58:30] Server Plugins
[07:58:30] --------------
[07:58:30]  Loading plugin: mysql
[07:58:30]  >> plugin.mysql: R41-4 successfully loaded.
[07:58:30]   Loaded.
[07:58:30]  Loaded 1 plugins.

[07:58:31] 
[07:58:31] Filterscripts
[07:58:31] ---------------
[07:58:31]   Loaded 0 filterscripts.

[07:58:35] [MySQL] Failed the connection to "phpMyAdmin".

[07:58:35] Number of vehicle models: 0
[07:58:35] --- Server Shutting Down.
[07:58:35] plugin.mysql: Unloading plugin...
[07:58:35] plugin.mysql: Plugin unloaded.
logs that successfully connected to mysql phpmyadmin

Код HTML:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7-R2, ©2005-2015 SA-MP Team

[07:59:05] filterscripts = ""  (string)
[07:59:05] 
[07:59:05] Server Plugins
[07:59:05] --------------
[07:59:05]  Loading plugin: mysql
[07:59:06]  >> plugin.mysql: R41-4 successfully loaded.
[07:59:06]   Loaded.
[07:59:06]  Loaded 1 plugins.

[07:59:06] 
[07:59:06] Filterscripts
[07:59:06] ---------------
[07:59:06]   Loaded 0 filterscripts.

[07:59:06] [MySQL] Successfully made a connection to "phpMyAdmin".

[07:59:06] Number of vehicle models: 0
Reply

TIL this:

Код:
main()
{
	func("Hello\0        ");
	return 1;
}
func(str[])
{
	strcat(str, " world!", 15);
	print(str);
	return 1;
}
You now can use strcat with a constant string (idk if i'm correct for this name) passed as parameter.

A better example:

Код:
CMD:sellcar(playerid, params[])
{
	ShowPlayerSafeDialog(playerid,
		"Are you sure you want to sell your vehicle?\0 Everything here will be ignored, this is just to create a longer string");
	return 1;
}
ShowPlayerSafeDialog(playerid, info[])
{
	strcat(info, "\n\nType your password to continue:", 117);
	ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, " ", info, "Continue", "Cancel");
	return 1;
}
This isn't quite good because sizeof() doesn't work on this strings but it is still interesting.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)