precision data logging for research purposes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 5ant1

Hi there, I might have a some what unusual question… I’m a novice when it comes to making video games, but my interest in it is growing by the minute and I was just wondering how plausible it is to create a game using godot that would collect research quality data.
I’m a behavioural scientist and I think it would be cool to design games to explore people’s decisions in a cooperative paradigm/game (I’ve always criticised the typically odd and ugly looking experiments currently used for this).
By data I mean, .csv files logging for example frequency of button presses, response time (in ms), xy cursor coordinates (at a 60 Hz rate), etc. I wonder if this would be possible and whether this would compromise both the speedy performance of the game as well as memory overload etc.

:bust_in_silhouette: Reply From: rolfpancake

The points you mentioned are perfectly doable with Godot. I can totally recommend using it because building a working prototype with the functions you need wouldn’t take too much time. I used python a lot to prototype scientific apps but when it comes to GUI things are getting messy.

Regarding your specific points:

csv files logging
Write a function converting a row of data into csv-format (e.g. sometimes it is needed to convert . to , in float numbers and then , to ; for seperating entries). Then you can use the same technique which is used to create save-games:

func to_csv(content):
    ...    # add some logic here
    return csv_formatted_content

func log_to_file(logfile_path, content_table):
	var logfile = File.new()
	logfile.open(logfile_path, File.WRITE)
	for row in content_table:
		logfile.store_line(to_csv(row))
	logfile.close()

frequency of button presses
Use signals or define your own button logic. There are countless possibilites.

onready var button_xyz = get_node("button_xyz")
onready var button_xyz_pressed_amount = 0

func _ready():
    button_xyz.connect("pressed", self, "_on_button_xyz_pressed")

func _on_button_xyz_pressed():
    button_xyz_pressed_amount += 1

response time (in ms)
Create a timer. Set wait_time to 0.001.

onready var timer = get_node("timer")
onready var reaction_button = get_node("reaction_button")
onready var time = 0

func _ready():
    timer.connect("timeout", self, "_on_timer_timeout")
    reaction_button.connect("pressed", self, "_on_reaction_button_pressed")
    timer.start()

func _on_reaction_button_pressed():
    timer.stop()
    print(time)

func _on_timer_timeout():
    time += wait_time

xy cursor coordinates
You can use the input-events or ask the viewport for mouse coordinates.

func _input(event):
    print(event.position)

Wow man! Thank you so much, I have coded some experiment in python and I totally agree with you regarding the GUI (which is why I’ve been wondering about this alternative). I really appreciate your taking the time to answer my query and the very, very useful details, you’re a good lad! :wink:

5ant1 | 2018-02-19 20:32

You are welcome. If you get any trouble building your application don’t hesitate to ask here again.

And if you are actually using Godot for science stuff, let the people on Reddit/Twitter/Facebook know. They like awesome stuff like that :wink:

rolfpancake | 2018-02-19 23:27

Hi

It’s really nice to find only one post regarding this query. Please share your experiences regarding logging for research purposes, also any developments and problems/solutions you faced/found. It will be really helpful as I am also trying to extract data (coordinates, moves, clicks etc) from a board game so that it can be used for research purposes.

hsn | 2019-10-29 23:47