質問編集履歴
4
質問したきっかけのコードを乗せました(結構長いです)
title
CHANGED
File without changes
|
body
CHANGED
@@ -63,4 +63,9 @@
|
|
63
63
|
print(temp_list)
|
64
64
|
|
65
65
|
sub.temp()
|
66
|
-
```
|
66
|
+
```
|
67
|
+
|
68
|
+
### 質問の背景
|
69
|
+
discord.pyを使ってターン制RPGBotを開発しています。
|
70
|
+
コード汚くてわからないかもですが、githubに一応載せておきます。
|
71
|
+
https://github.com/amano2/BitRPG/blob/master/code[URL※汚、長、コード注意]
|
3
sampleの誤りを修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -38,13 +38,13 @@
|
|
38
38
|
|
39
39
|
import sub
|
40
40
|
temp1, temp2 = sub.temp(10) # この段階でtemp1, temp2の中身が変わってほしい
|
41
|
+
print(temp1, temp2)
|
41
42
|
```sub.py
|
42
43
|
```py
|
43
44
|
# return で二つの値を返してみる
|
44
45
|
def temp(num):
|
45
46
|
temp1 = num
|
46
47
|
temp2 = num*2
|
47
|
-
print(temp1, temp2)
|
48
48
|
return temp1, temp2
|
49
49
|
```
|
50
50
|
関数内で処理を行っている間に、どうしても変数の中身を変えるタイミングをずらすわけにはいかず、結局よくわからないまま断念。
|
2
sampleの誤りを修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -41,7 +41,7 @@
|
|
41
41
|
```sub.py
|
42
42
|
```py
|
43
43
|
# return で二つの値を返してみる
|
44
|
-
def temp(num)
|
44
|
+
def temp(num):
|
45
45
|
temp1 = num
|
46
46
|
temp2 = num*2
|
47
47
|
print(temp1, temp2)
|
1
sample追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,4 +48,19 @@
|
|
48
48
|
return temp1, temp2
|
49
49
|
```
|
50
50
|
関数内で処理を行っている間に、どうしても変数の中身を変えるタイミングをずらすわけにはいかず、結局よくわからないまま断念。
|
51
|
-
詳しく言うと、temp1やtemp2にあたる物がlistで、そのlistに特定の要素が入っているか否かで処理が変わるため、そこら辺のいい方法が分からなかった。
|
51
|
+
詳しく言うと、temp1やtemp2にあたる物がlistで、そのlistに特定の要素が入っているか否かで処理が変わるため、そこら辺のいい方法が分からなかった。
|
52
|
+
こんな感じ
|
53
|
+
main.py
|
54
|
+
```py
|
55
|
+
temp_list = []
|
56
|
+
|
57
|
+
def temp():
|
58
|
+
global temp_list
|
59
|
+
if len(temp_list) > 0:
|
60
|
+
print("A")
|
61
|
+
else:
|
62
|
+
temp_list.append(0)
|
63
|
+
print(temp_list)
|
64
|
+
|
65
|
+
sub.temp()
|
66
|
+
```
|