Jump to content

Python syntax not quite right


Recommended Posts

  • Active Member

Hey guys,

someone can help me with this?  I need to call it in OnUpdate(): in root/game.py function.

Spoiler

def getModule():
		self.EnvironmentData = {
			# Explanation:
				# 16 - (16:00:00 - 16:59:59)
				# "d:/ymir work/environment/capedragonhead.msenv" - Environment what will be set on this time.
			# You can add how many environments you want.
			4:	"d:/ymir work/environment/metin2_map_n_flame_dragon_01.msenv",
			8:	"d:/ymir work/environment/mtthunder.msenv",
			12:	"d:/ymir work/environment/bayblacksand.msenv",
			16:	"d:/ymir work/environment/capedragonhead.msenv",
			20:	"d:/ymir work/environment/snowm02.msenv",
			22:	"d:/ymir work/environment/trent02.msenv"
		}
		return self.EnvironmentData # Returns the dict with all items

	def getHour():
		return ((app.GetGlobalTimeStamp() / 60) / 60 % 24) # Returns the hour from server timestamp (loaded by TPacketGCTime) 

	def Main():
		for key, c_pszName in getModule().iteritems():
			if getHour() is key and app.IsExistFile(c_pszName): # Checks if current hour is equal with index from dict EnvironmentData and it checks if environment exists (file .msenv) in pack.
				background.RegisterEnvironmentData(0, c_pszName) # Set the environment
				background.SetEnvironmentData(0)

 

Error in sysser:

Spoiler

1208 23:05:17087 ::   File "game.py", line 1552, in OnUpdate

1208 23:05:17087 ::   File "game.py", line 1604, in Main

1208 23:05:17087 :: NameError
1208 23:05:17087 :: : 
1208 23:05:17087 :: global name 'getModule' is not defined
1208 23:05:17087 :: 

 

Thanks for answers!

Sincerely,

ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Active Member

@xUniverse 

I placed it on the end of the file and edited to self

Spoiler

def getModule(self):
		self.EnvironmentData = {
			# Explanation:
				# 16 - (16:00:00 - 16:59:59)
				# "d:/ymir work/environment/capedragonhead.msenv" - Environment what will be set on this time.
			# You can add how many environments you want.
			4:	"d:/ymir work/environment/metin2_map_n_flame_dragon_01.msenv",
			8:	"d:/ymir work/environment/mtthunder.msenv",
			12:	"d:/ymir work/environment/bayblacksand.msenv",
			16:	"d:/ymir work/environment/capedragonhead.msenv",
			20:	"d:/ymir work/environment/snowm02.msenv",
			22:	"d:/ymir work/environment/trent02.msenv"
		}
		return self.EnvironmentData # Returns the dict with all items

	def getHour(self):
		return ((app.GetGlobalTimeStamp() / 60) / 60 % 24) # Returns the hour from server timestamp (loaded by TPacketGCTime) 

	def Main(self):
		for key, c_pszName in getModule().iteritems():
			if getHour() is key and app.IsExistFile(c_pszName): # Checks if current hour is equal with index from dict EnvironmentData and it checks if environment exists (file .msenv) in pack.
				background.RegisterEnvironmentData(0, c_pszName) # Set the environment
				background.SetEnvironmentData(0)

 

But idk how to execute this functions.

I'll be always helpful! 👊 

Link to comment
Share on other sites

This is the code of register environment based on time from VegaS,

Paste the three functions at the end of game.py (without self between parenthesis! )

	def getModule():
		self.EnvironmentData = {
			# Explanation:
				# 16 - (16:00:00 - 16:59:59)
				# "d:/ymir work/environment/capedragonhead.msenv" - Environment what will be set on this time.
			# You can add how many environments you want.
			4:	"d:/ymir work/environment/metin2_map_n_flame_dragon_01.msenv",
			8:	"d:/ymir work/environment/mtthunder.msenv",
			12:	"d:/ymir work/environment/bayblacksand.msenv",
			16:	"d:/ymir work/environment/capedragonhead.msenv",
			20:	"d:/ymir work/environment/snowm02.msenv",
			22:	"d:/ymir work/environment/trent02.msenv"
		}
		return self.EnvironmentData # Returns the dict with all items

	def getHour():
		return ((app.GetGlobalTimeStamp() / 60) / 60 % 24) # Returns the hour from server timestamp (loaded by TPacketGCTime) 

	def Main():
		for key, c_pszName in getModule().iteritems():
			if getHour() is key and app.IsExistFile(c_pszName): # Checks if current hour is equal with index from dict EnvironmentData and it checks if environment exists (file .msenv) in pack.
				background.RegisterEnvironmentData(0, c_pszName) # Set the environment
				background.SetEnvironmentData(0)

Then go to def OnUpdate(self) and put Main() before app.UpdateGame():

	def OnUpdate(self):	
		Main()
		app.UpdateGame()
		#...

Finally go to def OnOpen(self) and do the same:

	def Open(self):
		Main()
		app.SetFrameSkip(1)
		#...

I've not tested it. Give a try and tell me if it works!

Link to comment
Share on other sites

  • Active Member

@xUniverse Thanks for answer!

But I got this error:

Spoiler

1220 21:22:34946 ::   File "uiPhaseCurtain.py", line 61, in OnUpdate

1220 21:22:34946 ::   File "networkModule.py", line 150, in __ChangePhaseWindow

1220 21:22:34946 ::   File "game.py", line 144, in Open

1220 21:22:34948 :: NameError
1220 21:22:34948 :: : 
1220 21:22:34948 :: global name 'Main' is not defined
1220 21:22:34948 :: 
 

 

I'll be always helpful! 👊 

Link to comment
Share on other sites

En 20/12/2018 a las 17:25, ReFresh dijo:

@xUniverse Thanks for answer!

But I got this error:

  Hide contents

1220 21:22:34946 ::   File "uiPhaseCurtain.py", line 61, in OnUpdate

1220 21:22:34946 ::   File "networkModule.py", line 150, in __ChangePhaseWindow

1220 21:22:34946 ::   File "game.py", line 144, in Open

1220 21:22:34948 :: NameError
1220 21:22:34948 :: : 
1220 21:22:34948 :: global name 'Main' is not defined
1220 21:22:34948 :: 
 

 

Did you edit OnUpdate of uiPhaseCurtain.py? You must change OnUpdate from game.py

And my last reply had an error, I've just edited it (you must add Main() before app.UpdateGame() and before app.SetFrameSkin(1))

Link to comment
Share on other sites

  • Active Member

@xUniverse What should I change in uiPhaseCurtain.py? 

I got this error now:

Spoiler

1221 22:26:16076 ::   File "uiPhaseCurtain.py", line 62, in OnUpdate

1221 22:26:16076 ::   File "networkModule.py", line 150, in __ChangePhaseWindow

1221 22:26:16076 ::   File "game.py", line 167, in Open

1221 22:26:16076 :: NameError
1221 22:26:16076 :: : 
1221 22:26:16076 :: global name 'Main' is not defined
1221 22:26:16076 :: 

 

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • Forum Moderator

The code which you tried is called Python Inner Functions, and for use it you have to declare it inside of another function and call it.
Delete it and put this:

  • root/game.py
#Search for:
		self.SetSize(wndMgr.GetScreenWidth(), wndMgr.GetScreenHeight())
# Add after:
		### START OF REGISTER ENVIRONMENT BASED ON SERVER TIME
		self.environmentInfoDict = {
			4:	'd:/ymir work/environment/metin2_map_n_flame_dragon_01.msenv',
			8:	'd:/ymir work/environment/mtthunder.msenv',
			12:	'd:/ymir work/environment/bayblacksand.msenv',
			16:	'd:/ymir work/environment/capedragonhead.msenv',
			20:	'd:/ymir work/environment/snowm02.msenv',
			22:	'd:/ymir work/environment/trent02.msenv'
		}
		
		environmentHour = (app.GetGlobalTimeStamp() / 60) / 60 % 24
		if environmentHour in self.environmentInfoDict:
			environmentFileName = self.environmentInfoDict.get(environmentHour, constInfo.ENVIRONMENT_NIGHT)
			if app.IsExistFile(environmentFileName):
				background.RegisterEnvironmentData(0, environmentFileName)
				background.SetEnvironmentData(0)
			else:
				dbg.TraceError('Cannot find environment file (name: {:s})'.format(environmentFileName))
		### END OF REGISTER ENVIRONMENT BASED ON SERVER TIME

 

  • Love 1
Link to comment
Share on other sites

  • Active Member

@VegaS™ Thanks for your answer, but it doesn't work right.

When I place it in def OnUpdate(self): it works if it's before app.UpdateGame(), but when I place it after app.UpdateGame() it will be glitched and it won't work, here you can see the glitch:

I also need to extend it by:

Spoiler
if not self.__IsXMasMap():
	return

 

to make some maps as exclude from changing environment based on server time. When I tried to extend it by above mentioned if statement it will work but in map I can't see my character.

Edited by ReFresh

I'll be always helpful! 👊 

Link to comment
Share on other sites

  • 1 month later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.