Calling Custom Functions

正在查看此主题的用户

Kodashi

Sergeant
How does Warband handle custom functions?  I've created several functions but I am unsure how to define them in context of calling from within the game.

Any advice would be appreciated.
 
The preface of my project is to create something similar to c-rpg but without a PvP focus.  I guess you can say it's nore similar in context to Full Invasion with persistance handled with database extensions. 

I've created several functions that call Stored Procedures within my databse (MSSQL) which work just fine by themselves.  Here is an example of my code:

import _mssql

SQLServer = 'SQLServer\INSTANCE1'
Login = 'Login'
Password = 'xxxx'
Database = 'xxx'
conn = _mssql.connect(server=SQLServer, user=Login, password=Password, database=Database)

def CreateNewCharacter(UniqueID,Name):
  conn.execute_scalar("""exec CreateNewCharacter %s, %s""",(UniqueID,Name)) # calls stored procedure to handle transactions within the database
  conn.close()

 
My disconnect is that I guess I don't know enough about the module system and how to get Warband to recognize and call the custom python functions in order to facilitate transactions between application and database.  I'm trying to figure out how to get the system to push game variables to and read them from the database using this method.

My hope is to eventually release the package after I can get it all figured out.
 
Kodashi 说:
My disconnect is that I guess I don't know enough about the module system and how to get Warband to recognize and call the custom python functions in order to facilitate transactions between application and database.
AFAIK, you can't call other functions from MS, apart from those defined in header_operations.py.

You can externally analyze character export file though. And there should be other server-side files for characters too, I'm not knowledgeable in WM side of this. Look though crpg source, chadz made it available god bless him.
 
Yeah I was looking that over.  It looks as though He does his database transactions via http calls using another layer of processing; PHP I think.  I could probably do the same thing using .ASP but I was really hoping to avoid adding too many layers of complexity :smile:

So what I want to do isn't possible? Darn.
 
The game does not use python at all; it is only used to convert the module system data from a human readable format to the numbers in the txt files the game uses - basically, python is used to implement the compiler. You can use python as a sort of "preprocessor" as well, generating module system code at build time.
 
Actually it does use Python to some extent.

For example, this code is in Native. You can use reg(xNumber) to get a regx from a number.
插入代码块:
def reg(reg_no):
  if (reg_no < 0):
    print ("Error register_no negative")
    cause_error()
  return opmask_register | reg_no

So, logically, we could do something like this to get the local variable of a string no. Usage would be (assign, ":local_var", string_to_var(s0). Now our s0 should be in ":local_var" (not actually sure if you can do this with strings, tho').
插入代码块:
#RPW.
#String-to-local variable converter.  
def string_to_var(svar_no):
  if (svar_no < 0):
    print ("RPW Error at svar func.")
	cause_error()
  return opmask_local_variable | svar_no

It's hypothetical, but yea, it should work.
 
To use custom functions, you have to make scripts - If they are a try-catch type, you have to call them "script_cf_<script_name>" - can fail.
 
Sinisterius 说:
Actually it does use Python to some extent.
That's exactly what I meant by using it as a preprocessor; similar to how the C / C++ one works, to generate code or convert data - but only at compile time.

Your code would only return the number representing the corresponding register for the string register - reg1 for s1, reg2 for s2... you might as well just write reg in front rather than s (unless you have some fancy script / "code" generator for at build time).
 
Anyway yeah, you probably won't ever need that kind of an operation. I just wrote a quick example.
 
Lumos 说:
To use custom functions, you have to make scripts - If they are a try-catch type, you have to call them "script_cf_<script_name>" - can fail.

I see. 

Is there any documentation on scripting of this type?
 
Kodashi 说:
Lumos 说:
To use custom functions, you have to make scripts - If they are a try-catch type, you have to call them "script_cf_<script_name>" - can fail.
I see. 
Is there any documentation on scripting of this type?
Module system scripts consist of the same set of MS internal functions I told you. No outside code linkage is possible
 
后退
顶部 底部