-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSurvey.gd
More file actions
73 lines (60 loc) · 2.12 KB
/
Survey.gd
File metadata and controls
73 lines (60 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
extends Node
var random = RandomNumberGenerator.new()
var state = 0
var buttonDelay = 1
export var websocket_url = "ws://70.95.172.59:8765"
var _client = WebSocketClient.new()
var Q1_ANS
var Q2_ANS
var Q3_ANS
func _ready():
_client.connect("connection_closed", self, "_closed")
_client.connect("connection_error", self, "_closed")
_client.connect("connection_established", self, "_connected")
_client.connect("data_received", self, "_on_data")
# Initiate connection to the given URL
var err = _client.connect_to_url(websocket_url)
if err != OK:
print("Unable to connect")
set_process(false)
set_process_input(true)
func _process(delta):
$HSlider/yourAnswer/answer.text = str($HSlider.value)
_client.poll()
func _closed(was_clean = false):
# was_clean will tell you if the disconnection was correctly notified
# by the remote peer before closing the socket.
print("Closed, clean: ", was_clean)
set_process(false)
func _connected(proto = ""):
print("Connected with protocol: ", proto)
_send_data(Handshakes._get_handshake())
func _on_data():
# Print the received packet, you MUST always use get_peer(1).get_packet
# to receive data from server, and not get_packet directly when not
# using the MultiplayerAPI.
var data = _client.get_peer(1).get_packet().get_string_from_utf8()
print("Survey data from server: ", data)
func _send_data(data):
_client.get_peer(1).put_packet(JSON.print(data).to_utf8())
func _on_Submit_pressed():
if $Submit.text == 'Next Page':
Q1_ANS = $HSlider.value
$Submit.text = 'Submit'
$Q3.visible = true
$Q1.text = 'How good do you think you are at mental math?'
$HSlider/vdiff.text = 'I think I am very' + '\r\n' + 'good at mental math'
$HSlider/ndiff.text = 'I think I am very' + '\r\n' + 'bad at mental math'
$HSlider.value = 50
else:
Q3_ANS = 'None'
Q2_ANS = $HSlider.value
for child in $Q3.get_children():
if child.pressed:
Q3_ANS = child.text
_send_data({'sid':GlobalVars.sid + '_survey', 'Q1_diff':Q1_ANS, 'Q2_mental': Q2_ANS, 'Q3': Q3_ANS})
$Q1.visible = false
$Q3.visible = false
$HSlider.visible = false
$Submit.visible = false
$Label.visible = true