teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

誤字の修正

2020/03/22 14:17

投稿

_Beginner
_Beginner

スコア103

title CHANGED
File without changes
body CHANGED
@@ -56,7 +56,7 @@
56
56
 
57
57
  ##追記2
58
58
 
59
- ####例外 **Input string was not in a correct format.** 発生する件について
59
+ ####例外 __Input string was not in a correct format.__ 発生する件について
60
60
 
61
61
  ```C#
62
62
  void Start()
@@ -98,7 +98,7 @@
98
98
  ちなみに、例外処理が起きるということは戻る数値も正しくないのでエラーにしちゃったほうがいいですよね?
99
99
  (適当な数字を戻して上書きしてしまったりするのを防ぐにはエラーにする以外あるのでしょうか。)
100
100
 
101
- ######エラー内容
101
+ ######エラー(例外)内容
102
102
  > System.FormatException: Input string was not in a correct format.
103
103
  at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00057] in <567df3e0919241ba98db88bec4c6696f>:0
104
104
  at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00013] in <567df3e0919241ba98db88bec4c6696f>:0

4

追記2を追加

2020/03/22 14:17

投稿

_Beginner
_Beginner

スコア103

title CHANGED
File without changes
body CHANGED
@@ -42,8 +42,7 @@
42
42
 
43
43
  **GetValue()**の流れを、numに値が入って戻り値となるまで止めることはできるのでしょうか。
44
44
 
45
- ---
46
- 追記
45
+ ##追記
47
46
 
48
47
  **num = int.Perse(snapshot.ToString())**の下とかに**GotValue(num)**なんて付けて、
49
48
  ```C#
@@ -52,4 +51,61 @@
52
51
  Debug.Log(i);
53
52
  }
54
53
  ```
55
- こんな風にしたら楽なんですけど、取得したい値のキーはこれだけじゃなくて、汎用性がなくなっちゃうので、非同期処理を待つようなことはできないか知りたいです。
54
+ こんな風にしたら楽なんですけど、取得したい値のキーはこれだけじゃなくて、汎用性がなくなっちゃうので、非同期処理を待つようなことはできないか知りたいです。
55
+
56
+
57
+ ##追記2
58
+
59
+ ####例外 **Input string was not in a correct format.** 発生する件について
60
+
61
+ ```C#
62
+ void Start()
63
+ {
64
+ Invoke("GetVal", 5);
65
+ }
66
+
67
+ private async void GetVal()
68
+ {
69
+ int getScore = await FirebaseController.GetIntOfInformation("Score");
70
+ Debug.Log("Score"); //ここでスコアを取得したい
71
+ }
72
+
73
+ public async Task<int> GetIntOfInformation(string name)
74
+ {
75
+ try
76
+ {
77
+ var snapshot = await FirebaseDatabase.DefaultInstance
78
+ .GetReference("USERS")
79
+ .Child(id) //ユーザー識別(FirebaseAuthment)で取得したユーザーid
80
+ .Child("Information")
81
+ .Child(name)
82
+ .GetValueAsync().ConfigureAwait(false);
83
+
84
+ return int.Parse(snapshot.ToString());
85
+ }
86
+ catch (Exception exception)
87
+ {
88
+ Debug.LogError(exception);
89
+ return 0;
90
+ }
91
+
92
+ }
93
+ ```
94
+
95
+ このコードで**Debug.LogError(exception);**が常に呼び出されてしまいます。
96
+ Firebaseコンソール上では __USERS/"ユーザーid"/Information/Score__に値が入っています。
97
+
98
+ ちなみに、例外処理が起きるということは戻る数値も正しくないのでエラーにしちゃったほうがいいですよね?
99
+ (適当な数字を戻して上書きしてしまったりするのを防ぐにはエラーにする以外あるのでしょうか。)
100
+
101
+ ######エラー内容
102
+ > System.FormatException: Input string was not in a correct format.
103
+ at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x00057] in <567df3e0919241ba98db88bec4c6696f>:0
104
+ at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00013] in <567df3e0919241ba98db88bec4c6696f>:0
105
+ at System.Int32.Parse (System.String s) [0x00007] in <567df3e0919241ba98db88bec4c6696f>:0
106
+ at FirebaseController+<GetIntOfInformation>d__10.MoveNext () [0x000cd] in C:\Users\users\UnityProjects\project\Assets\FirebaseController.cs:133
107
+ UnityEngine.Debug:LogError(Object)
108
+ <GetIntOfInformation>d__10:MoveNext() (at C:/Users/user/UnityProjects/TestProject/Assets/FirebaseController.cs:137)
109
+ System.Threading.Tasks.TaskCompletionSource`1:SetResult(DataSnapshot)
110
+ Firebase.Database.<WrapInternalDataSnapshotTask>c__AnonStorey0:<>m__0(Task`1) (at Z:/tmp/tmp.hapPVC8cw6/firebase/database/client/unity/proxy/Query.cs:139)
111
+ System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()

3

コードの修正

2020/03/22 14:12

投稿

_Beginner
_Beginner

スコア103

title CHANGED
File without changes
body CHANGED
@@ -7,9 +7,8 @@
7
7
 
8
8
  ```C#
9
9
  int i = 0;
10
- void GetValue()
10
+ void GetValue(string path)
11
11
  {
12
- string path = ?? //欲しい情報;
13
12
  i = GetIntOfInformation(path);
14
13
  Debug.Log(i);
15
14
  }
@@ -18,7 +17,6 @@
18
17
  {
19
18
  int num = 0;
20
19
  FirebaseDatabase.DefaultInstance
21
- .GetReference(id)
22
20
  .Child("Information")
23
21
  .Child(path)
24
22
  .GetValueAsync().ContinueWith(task =>

2

GetIntOfInformation()の引数について修正

2020/03/19 13:23

投稿

_Beginner
_Beginner

スコア103

title CHANGED
File without changes
body CHANGED
@@ -9,7 +9,8 @@
9
9
  int i = 0;
10
10
  void GetValue()
11
11
  {
12
+ string path = ?? //欲しい情報;
12
- i = GetIntOfInformation();
13
+ i = GetIntOfInformation(path);
13
14
  Debug.Log(i);
14
15
  }
15
16
 
@@ -19,7 +20,7 @@
19
20
  FirebaseDatabase.DefaultInstance
20
21
  .GetReference(id)
21
22
  .Child("Information")
22
- .Child(name)
23
+ .Child(path)
23
24
  .GetValueAsync().ContinueWith(task =>
24
25
  {
25
26
  if (task.IsFaulted)

1

2020/03/19 13:19

投稿

_Beginner
_Beginner

スコア103

title CHANGED
@@ -1,1 +1,1 @@
1
- voidメソッドの中非同期で取得した値を入れたい
1
+ voidメソッドの中非同期で取得する値を待ちたい
body CHANGED
File without changes