• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] symbol already defined: "@yH_OnScriptInit@003"
#1
I tried to hook OnScriptInit
Here my main.pwn


Code:
#include <a_samp>

#undef ? MAX_PLAYERS
#define MAX_PLAYERS 100

#define YSI_NO_OPTIMISATION_MESSAGE
#define YSI_NO_CACHE_MESSAGE
#define YSI_NO_MODE_CACHE
#define YSI_NO_HEAP_MALLOC
#define YSI_NO_VERSION_CHECK

#include <a_mysql>
#include? ? <streamer>
#include? ? <sscanf2>
#include? ? <Pawn.CMD>

// YSI-Include 5.x
#include <YSI_Data/y_iterate>
#include <YSI_Coding/y_timers>

#include "test.pwn"
#include "test1.pwn"


test.pwn


Code:
#include <YSI_Coding/y_hooks>

hook OnScriptInit()
{
? ? print("test1");
? ? return 1;
}


test1.pwn


Code:
#include <YSI_Coding/y_hooks>

hook OnScriptInit()
{
? ? print("test2");
? ? return 1;
}


F:\samp\gamemodes\test1.pwn:4 (error) symbol already defined: "@yH_OnScriptInit@003"
Install by sampctl package install pawn-lang/[email protected]
  Reply
#2
Everytime you hook a callback using the `hook` macro, the final name of the callback becomes `hook <callback>@<unique_id>`. Now everytime you include `y_hooks` it generates a new unique number to append to the final callback name. Now as you might be aware, you can not have callbacks/functions of the same name, this doesn't compile.



Now this is what is happening with your issue, you have included `y_hooks` and have hooked the same callback twice, without including `y_hooks` again after the first hook. So the unique generated ID, is the same for each hook, which is why it is not working here. So to fix this issue, include `y_hooks` before you hook the next callback.



So this code below is bad.

Code:
#include <YSI_Coding\y_hooks>



hook OnPlayerConnect(playerid) // Final Callback Name -> OnPlayerConnect@001(playerid)

{

? ?return 1;

}



// This causes an error due to having the same name

hook OnPlayerConnect(playerid) // Final Callback Name -> OnPlayerConnect@001(playerid)

{

? ?return 1;

}



This is the fixed version that allows you to hook the same callback again

Code:
#include <YSI_Coding\y_hooks>



hook OnPlayerConnect(playerid) // Final Callback Name -> OnPlayerConnect@001(playerid)

{

? ?return 1;

}



#include <YSI_Coding\y_hooks>



hook OnPlayerConnect(playerid) // Final Callback Name -> OnPlayerConnect@002(playerid)

{

? ?return 1;

}
Remember to always refer to J0sh as `J0sh...`



@ Networks/Servers

San Andreas Gaming Network (Owner/Founder)

San Andreas Gaming (Owner/Founder)

Grand Theft Cop's n Robber's (Owner)

Britannia Roleplay (Owner/Founder) [Retired]

Alpine RP (Owner/Founder)

Aluminium Network (Maintainer) [Disbanded]

AlphaDM (Tech Support) [Disbanded]



# Services

forum.open.mp (Forum Manager) (Formerly Burgershot.gg

open.mp (Member)



~ Languages/Frameworks

Pawn, C, C, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,

Angular, React, Vue, Svelte, Laravel, Rocket
  Reply


Forum Jump: