I have a script very similar to the one at the end of the pygame example page, and I want to run it on startup to make the whole thing listen for commands on startup. I ran "crontab -e" and as a first line I put "@reboot python3 myscript.py". Upon rebooting, the script doesn't work, and returns pygame.error: video system not initialized. On the other hand, if I execute "python3 myscript.py" from the terminal, the script works.
The vast majority of answers simply notes that pygame.init() is not called, which is not the case here. According to a post translated from German, this can be solved by exporting a variable somewhere, but I am not sure where or how to do that.
Is there a way to give X11 privileges to the script ran on reboot by Crontab?
UPDATE: Upon chaining commands like Seamus suggested, setting DISPLAY=:0 doesn't work at all. From terminal after login, I did echo $DISPLAY and got :1. When setting:
@reboot (sleep 30; export DISPLAY=:1; python3 /full/path/to/myscript.py)
it starts working after login, but not before (which is my main requirement, as the device should be autonomous). I am not sure if this :1 is relevant and what is :0.