Sign in to follow this  
SenL

Example/template of character mod with level system?

Recommended Posts

Kzisor    1061
1 hour ago, SenL said:

I'm doing something wrong. Crashes on SendModRPCToServer()

1) I had to add "GLOBAL." before GetModRPCHandler() otherwise it crashes there. Am I missing something?

2) How come the AddModRPCHandler uses ExpOnChop where the function name is ExpOnChopFn?

Thanks for your continuous help!

1) Possibly, I thought it was added to the mod environment as that is MOD API. @PeterA could probably look into why we have to use GLOBAL.GetModRPCHandler() instead of simply using GetModRPCHandler() This is the entirely wrong function to be called.

2) That is a simple error, it should use ExpOnChop and the ExpOnChopFn should be renamed to ExpOnChop.

3) The reason you're crashing is because you modified the code in a way which you should not have modified it. I've fixed the code in the post above to reflect points 1 and 2. Simply copy and paste it over what you have and only change where it says [INSERT TAG HERE] everything else should be left the same otherwise it will not work.

Note: modname is a variable in the mod environment not something you need to replace.

Edited by Kzisor

Share this post


Link to post
Share on other sites
Kzisor    1061
36 minutes ago, Muche said:

1) I'm using SendModRPCToServer(MOD_RPC[modname]["my RPC name"]) and I don't need to use GLOBAL for this.

That is the same as using SendModRPCToServer( GetModRPC( modname, "my RPC name" ) ) (Edit: See below for what this means.)

The reason you need GLOBAL in front of GetModRPCHandle is because @PeterA forgot to add it to the mod environment.

Edited by Kzisor
Tpoy, tpyo, tyop.....stupid typos.

Share this post


Link to post
Share on other sites
Muche    295
14 minutes ago, Kzisor said:

That is the same as using SendModRPCToServer( GetModRPCHandle( modname, "my RPC name" ) )

If I'm reading GetModRPCHandler right, it returns actual function, not id_table that SendModRPCToServer is expecting.

Share this post


Link to post
Share on other sites
Kzisor    1061
2 hours ago, Muche said:

If I'm reading GetModRPCHandler right, it returns actual function, not id_table that SendModRPCToServer is expecting.

You're correct it's returning the function, which was a different issue altogether. I mis-remembered why it was created.

The way in which @PeterA originally explained it is that GetModRPCHandler is supposed to be used to obtain the Mod RPC function because he didn't want people having to play with the table arrays in order to use Mod RPC's; like you are describing which is bad coding practice from an API standpoint.

This is what the mod API should look like.

networkclientrpc.lua

function GetModRPC( namespace, name )
	return MOD_RPC[namespace][name]
end

modutils.lua

env.GetModRPCHandler = function( namespace, name )
	initprint("GetModRPCHandler", namespace, name)
	return GetModRPCHandler( namespace, name )
end

env.GetModRPC = function( namespace, name )
	initprint("GetModRPC", namespace, name)
	return GetModRPC( namespace, name )
end

Then what you would do is use GetModRPC for SendModRPCToServer; and to retrieve the function of the ModRPC you'd use GetModRPCHandler.

I will update the code above to fix this issue.

 

Edit:

@SenL I've updated the code in the original post notating the fixes need. I've created a GetModRPC function for you to use in order to obtain the table for the SendModRPCToServer function.

Edited by Kzisor
Fixed code error.

Share this post


Link to post
Share on other sites
PeterA    7823
1 hour ago, Kzisor said:

networkclientrpc.lua


function GetModRPC( namespace, name )
	return MOD_RPC[namespace][name]
end

modutils.lua


env.GetModRPCHandler = function( namespace, name )
	initprint("GetModRPCHandler", namespace, name)
	GetModRPCHandler( namespace, name )
end

env.GetModRPC = function( namespace, name )
	initprint("GetModRPC", namespace, name)
	return GetModRPC( namespace, name )
end

Yup you're right, I missed adding GetModRPCHandler to the environment. While it's not strictly required in the enviroment since you can access it in global, it does make sense to be in there. GetModRPC makes sense too, rather than having to access the MOD_RPC table directly.

 

Share this post


Link to post
Share on other sites
SenL    30

Kzisor:

I'm trying to add 2nd badge to the same mod and I'm having trouble figuring out what to do with StatusDisplaysPostInit().

It'd have MakeLevelBadge() and a new one MakeAnotherBadge() but I get "stack overflow" crash on _SetGhostMode because it's calling itself over and over and over.

 

Edit:

Fixed by changing _SetGhostMode to _SetGhostMode2 on the "MakeAnotherBadge()".

Right?

Edited by SenL

Share this post


Link to post
Share on other sites
Kzisor    1061
18 minutes ago, SenL said:

Kzisor:

I'm trying to add 2nd badge to the same mod and I'm having trouble figuring out what to do with StatusDisplaysPostInit().

It'd have MakeLevelBadge() and a new one MakeAnotherBadge() but I get "stack overflow" crash on _SetGhostMode because it's calling itself over and over and over.

 

Edit:

Fixed by changing _SetGhostMode to _SetGhostMode2 on the "MakeAnotherBadge()".

Right?

No actually I fixed the bug which was in that code after you made this comment.

self._SetGhostMode should actually be local _SetGhostMode.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this