Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] symbol already defined: "@[email protected]"

 
  • 0 Vote(s) - 0 Average
Pawn symbol already defined: "@[email protected]"
Zow
Offline

Burgershot Member
Posts: 34
Threads: 20
Joined: Apr 2019
Reputation: 0
Location: Malaysia
#1
2020-06-24, 06:19 AM (This post was last modified: 2020-06-24, 06:20 AM by Zow.)
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: "@[email protected]"
Install by sampctl package install pawn-lang/[email protected]
JustMichael
Offline

Forum Manager

Posts: 189
Threads: 3
Joined: Feb 2019
Reputation: 17
Location: England
#2
2020-06-24, 07:45 AM
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 -> [email protected](playerid)
{
   return 1;
}

// This causes an error due to having the same name
hook OnPlayerConnect(playerid) // Final Callback Name -> [email protected](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 -> [email protected](playerid)
{
   return 1;
}

#include <YSI_Coding\y_hooks>

hook OnPlayerConnect(playerid) // Final Callback Name -> [email protected](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)
Alpine RP (Owner/Founder)
Aluminium Network (Maintainer)
AlphaDM (Tech Support)

# Services
Burgershot.gg (Forum Manager)
open.mp (Member)

~ Languages/Frameworks
Pawn, C, C++, C#, Javascript, Typescript, Lua, Python, Go, Rust, PHP, SQL,
Angular, React, Vue, Svelte, Laravel, Rocket
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode