質問編集履歴

4

質問したきっかけのコードを乗せました(結構長いです)

2020/06/14 05:07

投稿

BitHell
BitHell

スコア1

test CHANGED
File without changes
test CHANGED
@@ -129,3 +129,13 @@
129
129
  sub.temp()
130
130
 
131
131
  ```
132
+
133
+
134
+
135
+ ### 質問の背景
136
+
137
+ discord.pyを使ってターン制RPGBotを開発しています。
138
+
139
+ コード汚くてわからないかもですが、githubに一応載せておきます。
140
+
141
+ https://github.com/amano2/BitRPG/blob/master/code[URL※汚、長、コード注意]

3

sampleの誤りを修正

2020/06/14 05:07

投稿

BitHell
BitHell

スコア1

test CHANGED
File without changes
test CHANGED
@@ -78,6 +78,8 @@
78
78
 
79
79
  temp1, temp2 = sub.temp(10) # この段階でtemp1, temp2の中身が変わってほしい
80
80
 
81
+ print(temp1, temp2)
82
+
81
83
  ```sub.py
82
84
 
83
85
  ```py
@@ -89,8 +91,6 @@
89
91
  temp1 = num
90
92
 
91
93
  temp2 = num*2
92
-
93
- print(temp1, temp2)
94
94
 
95
95
  return temp1, temp2
96
96
 

2

sampleの誤りを修正

2020/06/14 04:54

投稿

BitHell
BitHell

スコア1

test CHANGED
File without changes
test CHANGED
@@ -84,7 +84,7 @@
84
84
 
85
85
  # return で二つの値を返してみる
86
86
 
87
- def temp(num)
87
+ def temp(num):
88
88
 
89
89
  temp1 = num
90
90
 

1

sample追加

2020/06/14 04:52

投稿

BitHell
BitHell

スコア1

test CHANGED
File without changes
test CHANGED
@@ -99,3 +99,33 @@
99
99
  関数内で処理を行っている間に、どうしても変数の中身を変えるタイミングをずらすわけにはいかず、結局よくわからないまま断念。
100
100
 
101
101
  詳しく言うと、temp1やtemp2にあたる物がlistで、そのlistに特定の要素が入っているか否かで処理が変わるため、そこら辺のいい方法が分からなかった。
102
+
103
+ こんな感じ
104
+
105
+ main.py
106
+
107
+ ```py
108
+
109
+ temp_list = []
110
+
111
+
112
+
113
+ def temp():
114
+
115
+ global temp_list
116
+
117
+ if len(temp_list) > 0:
118
+
119
+ print("A")
120
+
121
+ else:
122
+
123
+ temp_list.append(0)
124
+
125
+ print(temp_list)
126
+
127
+
128
+
129
+ sub.temp()
130
+
131
+ ```