Skocz do zawartości
Masz już aplikację Sharegon?

Odkryj wszystkie możliwości. Dowiedz się więcej

Sharegon.pl

Zainstaluj aplikację Sharegon i korzystaj z powiadomień push oraz licznika nowych aktywności bezpośrednio z ekranu głównego.

Aby zainstalować tę aplikację na iOS i iPadOS.
  1. Tap the Share icon in Safari
  2. Przewiń menu i stuknij Dodaj do ekranu początkowego.
  3. Stuknij Dodaj w prawym górnym rogu.
Zainstaluj aplikację Sharegon na Androidzie
  1. Otwórz Sklep Google Play na swoim smarfonie.
  2. Wyszukaj „Sharegon” w pasku wyszukiwania.
  3. Stuknij „Zainstaluj”, aby pobrać aplikację.

Problem przy dodaniu tekstu "kanał" w pliku locale_game.txt - TypeError: 'an integer is required'

Aktywny

Featured Replies

Opublikowano

witam, zmieniłem kod na:

def NotifyChannelState(self, addrKey, state):
		if addrKey == 1:
			if state != 3:
				self.Channel1Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel1Button.SetText(localeInfo.CHANNEL + " 1 (" + STATE_DICT[state] + ")")
		if addrKey == 2:
			if state != 3:
				self.Channel2Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel2Button.SetText(localeInfo.CHANNEL + " 2 (" + STATE_DICT[state] + ")")
		if addrKey == 3:
			if state != 3:
				self.Channel3Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel4Button.SetText(localeInfo.CHANNEL + " 3 (" + STATE_DICT[state] + ")")
		if addrKey == 4:
			if state != 3:
				self.Channel4Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel4Button.SetText(localeInfo.CHANNEL + " 4 (" + STATE_DICT[state] + ")")
{
					"name": "Channel1Button",
					"type": "radio_button",
					"x": 10,
					"y": 10,
					"default_image": "d:/ymir work/ui/public/large_button_01.sub",
					"over_image": "d:/ymir work/ui/public/large_button_02.sub",
					"down_image": "d:/ymir work/ui/public/large_button_03.sub",
					"color": 4294281095L, 
                    "text": ".....",
				},

Lecz wyświetla "....." a powinno: "Kanał 1 (NORM)"

Logi z syser:

0315 17:41:00530 :: mouseModule:357: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
0315 17:41:00530 :: Traceback (most recent call last):
0315 17:41:00530 ::   File "mouseModule.py", line 357, in Update
0315 17:41:00530 :: TypeError
0315 17:41:00530 :: : 
0315 17:41:00530 :: an integer is required
0315 17:41:00530 :: 
0315 17:41:01393 :: Traceback (most recent call last):
0315 17:41:01393 ::   File "mouseModule.py", line 357, in Update
0315 17:41:01393 :: TypeError
0315 17:41:01393 :: : 
0315 17:41:01393 :: an integer is required
0315 17:41:01393 :: 
0315 17:41:01661 :: Traceback (most recent call last):
0315 17:41:01661 ::   File "mouseModule.py", line 357, in Update
0315 17:41:01661 :: TypeError
0315 17:41:01661 :: : 
0315 17:41:01661 :: an integer is required
0315 17:41:01661 :: 
0315 17:41:01945 :: Traceback (most recent call last):
0315 17:41:01945 ::   File "mouseModule.py", line 357, in Update
0315 17:41:01945 :: TypeError
0315 17:41:01945 :: : 
0315 17:41:01945 :: an integer is required
0315 17:41:01945 :: 

Co robię źle?

Rozwiązane przez benio101

Przejdź do rozwiązania
Opublikowano

Widze literówke


		if addrKey == 3:
			if state != 3:
				self.Channel3Button.SetFontColor(0.0, 1.0, 0.0)
			# 	z channel4button na channel 3 button	
				self.Channel3Button.SetText(localeInfo.CHANNEL + " 3 (" + STATE_DICT[state] + ")")	


Widzę też

TypeError: an integer is required

Spróbuj zamienić kolor na wartość szesnastkową, np.

def NotifyChannelState(self, addrKey, state):
    GREEN_COLOR = 0xff00ff00 

    if addrKey == 1:
        if state != 3:
            self.Channel1Button.SetFontColor(GREEN_COLOR)
        self.Channel1Button.SetText(localeInfo.CHANNEL + " 1 (" + STATE_DICT[state] + ")")

Daj znać czy działa

Opublikowano
  • Autor

Zrobiłem jak mówiłeś i teraz takie logi:

0315 18:34:00539 :: mouseModule:357: RuntimeWarning: tp_compare didn't return -1 or -2 for exception

0315 18:34:00540 :: Traceback (most recent call last):

0315 18:34:00540 ::   File "mouseModule.py", line 357, in Update

0315 18:34:00540 :: TypeError
0315 18:34:00540 :: : 
0315 18:34:00540 :: an integer is required
0315 18:34:00540 :: 

0315 18:34:01517 :: Traceback (most recent call last):

0315 18:34:01517 ::   File "mouseModule.py", line 357, in Update

0315 18:34:01518 :: TypeError
0315 18:34:01518 :: : 
0315 18:34:01518 :: an integer is required
0315 18:34:01518 :: 

0315 18:34:01909 :: Traceback (most recent call last):

0315 18:34:01909 ::   File "mouseModule.py", line 357, in Update

0315 18:34:01909 :: TypeError
0315 18:34:01909 :: : 
0315 18:34:01909 :: an integer is required
0315 18:34:01909 :: 

0315 18:34:02533 :: Traceback (most recent call last):

0315 18:34:02533 ::   File "mouseModule.py", line 357, in Update

0315 18:34:02533 :: TypeError
0315 18:34:02533 :: : 
0315 18:34:02533 :: an integer is required
0315 18:34:02533 :: 
Opublikowano
def NotifyChannelState(self, addrKey, state):
		if addrKey == 1:
			if state != 3:
				self.Channel1Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel1Button.SetText("Kanał 1 ({})".format(STATE_DICT[state]))
		if addrKey == 2:
			if state != 3:
				self.Channel2Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel2Button.SetText("Kanał 2 ({})".format(STATE_DICT[state]))
		if addrKey == 3:
			if state != 3:
				self.Channel3Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel3Button.SetText("Kanał 3 ({})".format(STATE_DICT[state]))
		if addrKey == 4:
			if state != 3:
				self.Channel4Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel4Button.SetText("Kanał 4 ({})".format(STATE_DICT[state]))

chyba tak

Opublikowano
  • Autor
18 minut temu, _daha_0 napisał(a):
def NotifyChannelState(self, addrKey, state):
		if addrKey == 1:
			if state != 3:
				self.Channel1Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel1Button.SetText("Kanał 1 ({})".format(STATE_DICT[state]))
		if addrKey == 2:
			if state != 3:
				self.Channel2Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel2Button.SetText("Kanał 2 ({})".format(STATE_DICT[state]))
		if addrKey == 3:
			if state != 3:
				self.Channel3Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel3Button.SetText("Kanał 3 ({})".format(STATE_DICT[state]))
		if addrKey == 4:
			if state != 3:
				self.Channel4Button.SetFontColor(0.0, 1.0, 0.0)
			self.Channel4Button.SetText("Kanał 4 ({})".format(STATE_DICT[state]))

chyba tak

To teraz takie coś wywala: 0315 20:00:00885 :: mouseModule:357: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
0315 20:00:00885 :: Traceback (most recent call last):
0315 20:00:00885 :: File "mouseModule.py", line 357, in Update
0315 20:00:00885 :: TypeError
0315 20:00:00885 :: :
0315 20:00:00885 :: an integer is required
0315 20:00:00885 ::

a w cliencie dalej "...."

Opublikowano
  • Autor
10 godzin temu, _daha_0 napisał(a):
File "mouseModule.py", line 357, in Update

Pokaż tą funkcje

O to ona:

def Update(self, x, y):
		self.x = x
		self.y = y
		if True == self.isAttached():
			if 0 != self.AttachedIconHandle:
				grpImage.SetDiffuseColor(self.AttachedIconHandle, 1.0, 1.0, 1.0, 0.5)
				grpImage.SetPosition(self.AttachedIconHandle, self.x - self.AttachedIconHalfWidth, self.y - self.AttachedIconHalfHeight)
				self.countNumberLine.SetPosition(self.x, self.y - self.AttachedIconHalfHeight - 3)
		if self.IsSoftwareCursor:
			if 0 != self.curCursorImage:
				self.curCursorImage.SetPosition(self.x + self.cursorPosX, self.y + self.cursorPosY)

Kolega podesłał mi takie coś lecz dalej ten sam błąd.

intrologin.py

STATE_DICT = {
	0:localeInfo.CHANNEL_STATUS_OFF,
	1:localeInfo.CHANNEL_STATUS_NORMAL,
	2:localeInfo.CHANNEL_STATUS_BUSY,
	3:localeInfo.CHANNEL_STATUS_FULL
}

self.channelButtonList = []
			self.channelButtonList.append(GetObject("Channel1Button"))
			self.channelButtonList.append(GetObject("Channel2Button"))
			self.channelButtonList.append(GetObject("Channel3Button"))
			self.channelButtonList.append(GetObject("Channel4Button"))

def NotifyChannelState(self, addrKey, state):
		if addrKey-1 < len(self.channelButtonList):
			status = STATE_DICT.get(state, STATE_DICT[0])
			self.channelButtonList[addrKey-1].SetText(localeInfo.CHANNEL + " %d (%s)" % (addrKey, status))

loginwindow.py

{
					"name": "Channel1Button",
					"type": "radio_button",
					"x": 10,
					"y": 10,
					"default_image": "d:/ymir work/ui/public/large_button_01.sub",
					"over_image": "d:/ymir work/ui/public/large_button_02.sub",
					"down_image": "d:/ymir work/ui/public/large_button_03.sub",  
					"color": 4294281095L,
					"text": ".....",
				},

locale_game.txt

CHANNEL_STATUS_OFF	test
CHANNEL_STATUS_NORMAL	Normal
CHANNEL_STATUS_BUSY	Busy
CHANNEL_STATUS_FULL	Full

Lecz logi dalej te same: sysser.txt

0316 06:10:00521 :: mouseModule:357: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
0316 06:10:00521 :: Traceback (most recent call last):
0316 06:10:00521 ::   File "mouseModule.py", line 357, in Update
0316 06:10:00521 :: TypeError
0316 06:10:00521 :: : 
0316 06:10:00521 :: an integer is required
0316 06:10:00521 ::
Opublikowano

Spróbuj zcastować na początku te zmienne, które powinny być intem do inta, czyli po prostu użyć na nie int(zmienna). Takie podejście "brute-force" niekoniecznie może być dobre, bo może jakiś inny problem wprowadzić. Lepszym podejściem byłoby jakbyś w tej funkcji po prostu najpierw wyprintował sobie typy wszystkich zmiennych w tej funkcji (type(zmienna).__name__), może się jakaś lampeczka zapali :)

Opublikowano
  • Autor

Działająca funkcja:

def __GetColoredChannelStatus(self, state):
		status = STATE_DICT.get(state, STATE_DICT[0])
		if state == 1:
			return "|cff00ff00%s|r" % status
		elif state == 3:	
			return "|cffff0000%s|r" % status
		elif state == 2:	
			return "|cffffff00%s|r" % status
		else:	
			return "|cffff0000%s|r" % status
	def NotifyChannelState(self, addrKey, state):
		try:
			addrKey = int(addrKey)
			state = int(state)
		except:
			return
		if addrKey < 1 or addrKey > len(self.channelButtonList):
			return
		status = self.__GetColoredChannelStatus(state)
		self.channelButtonList[addrKey - 1].SetText("%s %d (%s)" % (localeInfo.CHANNEL, addrKey, status))

Lecz nie zmienia kolor tekstu "Kanał 1 (OFF)"

Opublikowano
1 godzinę temu, benio101 napisał(a):

Działająca funkcja:

def __GetColoredChannelStatus(self, state):
		status = STATE_DICT.get(state, STATE_DICT[0])
		if state == 1:
			return "|cff00ff00%s|r" % status
		elif state == 3:	
			return "|cffff0000%s|r" % status
		elif state == 2:	
			return "|cffffff00%s|r" % status
		else:	
			return "|cffff0000%s|r" % status
	def NotifyChannelState(self, addrKey, state):
		try:
			addrKey = int(addrKey)
			state = int(state)
		except:
			return
		if addrKey < 1 or addrKey > len(self.channelButtonList):
			return
		status = self.__GetColoredChannelStatus(state)
		self.channelButtonList[addrKey - 1].SetText("%s %d (%s)" % (localeInfo.CHANNEL, addrKey, status))

Lecz nie zmienia kolor tekstu "Kanał 1 (OFF)"

Jeżeli masz na myśli, że "Kanał 1" nie ma zmienionego koloru to tak powinno być. Jeśli "OFF" nie ma zmienionego koloru to już by znaczyło jak na moje strzelam, że klient gry inny format oczekuje tekstu kolorowego. Musiałbyś wtedy zajrzeć w funkcje CGraphicTextInstance::Update, bądź CGraphicTextInstance::Render. Pro tip: szukaj po zmiennej - m_stText, bo to ona jest ustawiana w funkcji SetValue, czyli w pythonowym SetText. No chyba, że masz jakieś mocne customy, to już inna sprawa. Powodzenia!

Opublikowano
  • Autor

Na początku miałem tak:

def NotifyChannelState(self, addrKey, state):
		if addrKey == 1:
			if state != 3:
				self.Channel1Status.SetFontColor(0.0, 1.0, 0.0)
			self.Channel1Status.SetText(STATE_DICT[state])
		if addrKey == 2:
			if state != 3:
				self.Channel2Status.SetFontColor(0.0, 1.0, 0.0)
			self.Channel2Status.SetText(STATE_DICT[state])
		if addrKey == 3:
			if state != 3:
				self.Channel3Status.SetFontColor(0.0, 1.0, 0.0)
			self.Channel3Status.SetText(STATE_DICT[state])
		if addrKey == 4:
			if state != 3:
				self.Channel4Status.SetFontColor(0.0, 1.0, 0.0)
			self.Channel4Status.SetText(STATE_DICT[state])
		if addrKey == 5:
			if state != 3:
				self.Channel5Status.SetFontColor(0.0, 1.0, 0.0)
			self.Channel5Status.SetText(STATE_DICT[state])
		if addrKey == 6:
			if state != 3:
				self.Channel6Status.SetFontColor(0.0, 1.0, 0.0)
			self.Channel6Status.SetText(STATE_DICT[state])

"name": "Channel1Button",
					"type": "radio_button",
					"x": 10,
					"y": 12,
					"default_image": "d:/ymir work/ui/public/small_button_01.sub",
					"over_image": "d:/ymir work/ui/public/small_button_02.sub",
					"down_image": "d:/ymir work/ui/public/small_button_03.sub",

"name": "Channel1Status",
					"type": "text",
					"x": 30,
					"y": 33,
					"text_horizontal_align": "center",
					"color": 4294281095L,
					"text": ".....",

Lecz połączyłem kanały ze statusem i chce aby teraz cały tekst sie zmieniał:

  • Kanał 1 (Pełny)

A cały czas jest:

  • Kanał 1 (Pełny)

Mój aktualny kod gdzie nie działa tylko kolorowanie tekstu (0 logów)

def NotifyChannelState(self, addrKey, state):
		try:
			addrKey = int(addrKey)
			state = int(state)
		except:
			return
		if addrKey < 1 or addrKey > len(self.channelButtonList):
			return
		status = STATE_DICT.get(state, STATE_DICT[0])
		color_code = ""
		if state == 1:  
			color_code = "|cff00ff00"  
		elif state == 3:  
			color_code = "|cffff0000" 
		elif state == 2:  
			color_code = "|cffffff00"  
		else:  
			color_code = "|cffff0000"  
		channel_text = "%s %d (%s)" % (localeInfo.CHANNEL, addrKey, status)
	
		self.channelButtonList[addrKey - 1].SetFontColor(*self.__GetColoredChannelStatus(state)[0])
		self.channelButtonList[addrKey - 1].SetText(channel_text)

"name": "Channel1Button",
					"type": "radio_button",
					"x": 10,
					"y": 10,
					"default_image": "d:/ymir work/ui/public/large_button_01.sub",
					"over_image": "d:/ymir work/ui/public/large_button_02.sub",
					"down_image": "d:/ymir work/ui/public/large_button_03.sub",  
					"color": 4294281095,
					"text": ".....",
Opublikowano
  • Autor
  • Rozwiązanie

Temat można zamknać.

Rozwiazanie:

def NotifyChannelState(self, addrKey, state):
		try:
			addrKey = int(addrKey)
			state = int(state)
		except:
			return
		if addrKey < 1 or addrKey > len(self.channelButtonList):
			return
		status = STATE_DICT.get(state, STATE_DICT[0])
		color_code = ""
		if state == 1:  
			color_code = ""
		elif state == 3:  
			color_code = "|cff00ff00"
		elif state == 2:  
			color_code = "|cffffff00"  
		else:  
			color_code = "|cffff0000"  
		channel_text = "%s %d (%s)" % (localeInfo.CHANNEL, addrKey, status)
		if color_code:
			self.channelButtonList[addrKey - 1].SetText(color_code + channel_text + "|r")
		else:
			self.channelButtonList[addrKey - 1].SetText(channel_text)
Gość
Ten temat został zamknięty. Brak możliwości dodania odpowiedzi.

Konto

Nawigacja

Skonfiguruj powiadomienia push w przeglądarce.

Chrome (Android)
  1. Stuknij ikonę kłódki obok paska adresu.
  2. Wybierz Uprawnienia → Powiadomienia.
  3. Dostosuj swoje preferencje.
Chrome (Desktop)
  1. Kliknij ikonę kłódki na pasku adresu.
  2. Wybierz Ustawienia witryny.
  3. Znajdź Powiadomienia i dostosuj swoje preferencje.