• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Calling a function from another module using a dialog?
#1
While working on my gamemode I wanted to create a provisional control panel that would let the player do stuff that they would previously have to do through commands

However, since I've split my gamemode into modules and I don't want it to become a jumbled mess (if it isn't one already), I thought I should create a separate file for this control panel that I've called pControlPanel. The feature operates through a list dialog that presents the player with options, and it so happens that one of those options is supposed to call a function located inside another file called pvp_system.
Here's my file structure:

Code:
- gamemodes
? ?- crimewave.pwn
? ?
? ?- crimewave
? ? ? ?- gui
? ? ? ? ? ?- pControlPanel.inc
? ? ? ?- player
? ? ? ? ? ?- pvp_system.inc

And inside crimewave.pwn the files are included as follows

Code:
#include "crimewave/gui/pControlPanel.inc"
#include "crimewave/player/pvp_system.inc"

This is the dialog inside pControlPanel.inc made with easyDialog

Code:
Dialog:pControlPanel(playerid, response, listitem, inputtext[])
{
if(response)
? ?{
? ? ? ?switch(listitem)
? ? ? ?{
? ? ? ? ? ?case 0: ShowWeaponDialog(playerid);
? ? ? ? ? ?case 1: return 1;
? ? ? ? ? ?case 2: SetPlayerHealth(playerid, 0.0);
? ? ? ?}
? ?}
? ?return 1;
}

And this is the function inside pvp_system.inc?

Code:
ShowWeaponDialog(playerid)
{
? ?ShowPlayerDialog(yadda yadda...);
}

Now if I tried to compile that code I would get a "symbol is already defined"?on the line where i'm calling ShowWeaponDialog from the dialog function.?
To fix that I've tried using CallLocalFunction which lets the script compile but for some reason ShowWeaponDialog won't be called on runtime.?

As a last effort I tried making ShowWeaponDialog public and using CallRemoteFunction instead which makes the script work as intended, however I'm not sure that's the best solution because as far as I've been told ShowWeaponDialog should be called regardless of whether it's used in CallLocalFunction or CallRemoteFunction, in which case the code would be more complex than needs be

I'm very confused because afaik the #include directive practically joins files into one for the compiler so I'm really not sure why I'd have to use CallRemoteFunction for it to work

Anyone help? Ty
  Reply


Messages In This Thread
Calling a function from another module using a dialog? - by Metro - 2019-05-04, 05:15 PM

Forum Jump: