WB Coding Constants

Currently viewing this thread:

It is very annoying that there is a need to manually assign values to constants like slot_item_is_checked = 0. Is there a way that i can edit the process files to make them auto assign the values based on order of placement in the module_constants.py file?
 
Solution
I suck at python :grin: I took a look at the documentations. The problem is python considers first temp as global and the second one in the function as local. Here is a link to the explanation.
Proper code:
Code:
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher values

temp = slot_item_multiplayer_availability_linked_list_begin

def get_next_constant_value():
  global temp # makes the variable refer to the global one
  temp = temp + 1
  return temp

slot_custom_1 = get_next_constant_value()
slot_custom_2 = get_next_constant_value()
slot_custom_3 = get_next_constant_value()
slot_custom_4 = get_next_constant_value()
.
...

Eärendil Ardamírë

Subforum Moderator
WBWF&SM&B
You only need to assign a value to local variables. Global variables and slots get automatically a 0 assigned the first time you create them. For the rest it depends perhaps on what you are planning to do or what you need at specific situations, so setting them all automatically to specific values is not always possible.

Nice to see you back at modding btw :grin:
 
Upvote 0
I think you misunderstood his question (or i did :smile:)
From what i understood from his question, I think he's trying to create make "pyhon constants" auto assign like how ID files are created.
My advice is creating a temporary variable after last constant and using it to set them sequentially like this:
Code:
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher values
slot_custom_1 = 62
slot_custom_2 = 63
slot_custom_3 = 64
slot_custom_4 = 65
.
.
.
Code:
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher values
temp = slot_item_multiplayer_availability_linked_list_begin + 1
slot_custom_1 = temp
temp = temp + 1
slot_custom_2 = temp
temp = temp + 1
slot_custom_3 = temp
temp = temp + 1
slot_custom_4 = temp
.
.
.
 
Upvote 0
I think you misunderstood his question (or i did :smile:)
From what i understood from his question, I think he's trying to create make "pyhon constants" auto assign like how ID files are created.
My advice is creating a temporary variable after last constant and using it to set them sequentially like this:
Code:
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher values
slot_custom_1 = 62
slot_custom_2 = 63
slot_custom_3 = 64
slot_custom_4 = 65
.
.
.
Code:
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher values
temp = slot_item_multiplayer_availability_linked_list_begin + 1
slot_custom_1 = temp
temp = temp + 1
slot_custom_2 = temp
temp = temp + 1
slot_custom_3 = temp
temp = temp + 1
slot_custom_4 = temp
.
.
.
Thanks.
 
Upvote 0
When i think about it again, it was kinda lame:grin: With a function, it would be much neater.
Code:
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher values

temp = slot_item_multiplayer_availability_linked_list_begin

def get_next_constant_value():
  temp = temp + 1
  return temp
 
slot_custom_1 = get_next_constant_value()
slot_custom_2 = get_next_constant_value()
slot_custom_3 = get_next_constant_value()
slot_custom_4 = get_next_constant_value()
.
.
.
 
Upvote 0
When i think about it again, it was kinda lame:grin: With a function, it would be much neater.
Code:
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher values

temp = slot_item_multiplayer_availability_linked_list_begin

def get_next_constant_value():
  temp = temp + 1
  return temp

slot_custom_1 = get_next_constant_value()
slot_custom_2 = get_next_constant_value()
slot_custom_3 = get_next_constant_value()
slot_custom_4 = get_next_constant_value()
.
.
.
when i try your code i get a "local variable temp referenced before assignment".
 
Upvote 0
I suck at python :grin: I took a look at the documentations. The problem is python considers first temp as global and the second one in the function as local. Here is a link to the explanation.
Proper code:
Code:
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher values

temp = slot_item_multiplayer_availability_linked_list_begin

def get_next_constant_value():
  global temp # makes the variable refer to the global one
  temp = temp + 1
  return temp

slot_custom_1 = get_next_constant_value()
slot_custom_2 = get_next_constant_value()
slot_custom_3 = get_next_constant_value()
slot_custom_4 = get_next_constant_value()
.
.
.

Edit:
temp = temp + 1
can be replaced with
temp += 1
too. Unfortunately python doesn't seem to support ++ operator.
 
Last edited:
Upvote 0
Solution
I suck at python :grin: I took a look at the documentations. The problem is python considers first temp as global and the second one in the function as local. Here is a link to the explanation.
Proper code:
Code:
slot_item_multiplayer_availability_linked_list_begin = 61 #temporary, can be moved to higher values

temp = slot_item_multiplayer_availability_linked_list_begin

def get_next_constant_value():
  global temp # makes the variable refer to the global one
  temp = temp + 1
  return temp

slot_custom_1 = get_next_constant_value()
slot_custom_2 = get_next_constant_value()
slot_custom_3 = get_next_constant_value()
slot_custom_4 = get_next_constant_value()
.
.
.

Edit:

can be replaced with

too. Unfortunately python doesn't seem to support ++ operator.
Thanks! That worked.
 
Upvote 0
Top Bottom