Simple online game requirements?

230 views
Skip to first unread message

MFBBSubEsp

unread,
Dec 25, 2019, 12:57:20 AM12/25/19
to DroidScript
Hi all,
As some might remember I asked about the possibilities of p2p with Droidscript, of course as you have shown me this is not possible due the device limits in accepting connections, but I have read in this old thread that online shooter game is possible and relatively easy to achieve so I guess the trouble is I asked about p2p and not just online game development: 


So my question is, what is needed for that type of simple online game? Im now relatively familiar with Droidscript and Javascript but I have been using Glview until now in my little games, I have to tell the tool is impressively easy and fast to use and quite cool, will start with Game view next, anyway I would like to know the requirements in terms of knowledge or anything needed as I think a server is probably not needed or maybe can go with a free server or a web server like those we use to host our personal sites etc Thanks a lot for any clue about this and sorry if question sounds a bit vague, I couldnt find more information about online game here or in other sites.

Kallikratidas

unread,
Dec 25, 2019, 6:29:01 AM12/25/19
to DroidScript
Of course it is possible to make an online game with droidcript. I have made many online games. You can use firebase to begin (not the DroidScript plugin, it is awful and not free).

Check the server.js and the client.js I will upload above.( The client.js may be used from more than 1 devices, but the server.js no)

MFBBSubEsp

unread,
Dec 25, 2019, 12:06:42 PM12/25/19
to DroidScript
Thanks a lot for the info, i will check the firebase you mentioned as soon as i come home to my Droidscript coding device, however i cant see your files or maybe my phone displays things in a different way, can you check these are here please?

Kallikratidas

unread,
Dec 28, 2019, 7:09:11 AM12/28/19
to DroidScript
Ok I will upload them again in some hours because now I am bussy.
Message has been deleted

Kallikratidas

unread,
Dec 28, 2019, 6:00:59 PM12/28/19
to DroidScript
I made a more easier to understand example, commented with no errors.

Just follow my instructions:
1)Download client1 & client2 in different devices.
2)Create a firebase account.
3)Create a database. (NOT FILE CLOUDSTORE)
4)Copy your firebase config and paste it in each client.
5)Run the two clients.


If everything goes good, you should see the text you type from the device that uses client 2 to the other of the client 1.

I hope that helped you get a small idea of the firebase performance.

Test it and if you have any questions, an me.

client 1.spk
client 2.spk

MFBBSubEsp

unread,
Dec 28, 2019, 7:26:37 PM12/28/19
to DroidScript
Thanks a million Kallikatridas =), i owe you a big one, if you ever need a something let me know, i havent tried yet as i have a little technical issue in my coding device but im sure it will work perfectly, will comment if anything odd appears. By the way, since you mention this example you made passes text from one user to the other... i wonder, is it accurate to use this same method to send coordinates or keypresses to display the other player movement actions etc? I mean can we move in real time like this? I have seen examples of code made in Unity using Firebase and they seem to achieve almost real time movement but Droidscript examples are hard to see although i read here that any Javascript code that works in browser should work in Droidscript. By the way your games are published online? Would be cool to play them to see top edge we can reach =)

Kallikratidas

unread,
Dec 29, 2019, 4:05:24 AM12/29/19
to DroidScript
Of course you can make a player move through firebase.

But, because firebase is a websocket from a remote server in google, you must try a trick I also did to create a "server".

If you want to make something more commercial, you will definitely need to use the firebase database security rules.

If you want to make something for fun, I suggest you use the test mode.

If you want try the following unfinished game I am making:

*Use 2 phone devices and one computer.

*Open the game from the 2 devices.

*Open the server.html from any browser in your computer.

I will upload the Game.js and server.html latter that day, because I do not have my computer with that file here.

Server.html includes:
*Matchmaking for players.
*Battle servering.

The only thing is that, I have made it to handle only one game per time, because I wanted the highest performance.

Regards

MFBBSubEsp

unread,
Dec 29, 2019, 11:03:43 PM12/29/19
to DroidScript
Thanks a lot Kallikratidas, I havent tested this yet due my device being unusable as well as my emulator now but all you said makes lot of sense, however as Im new to all this and since I havent been able to see your code yet, there is one doubt in my head at the moment, you said you create a server to make it work better, but the clients are still connected to the Firebase as well as the server, right? I mean since all packets go through Firebase isnt it as fast as having 2 clients? I said this in relation to speed or performance, of course to have something like more than one game as you said a server is needed to organize things or else I assume everybody connects in the same already running match

Kallikratidas

unread,
Dec 30, 2019, 10:40:53 AM12/30/19
to DroidScript
Of course using a client as a server makes your game run slower. But try first the files I will upload and if you still want a higher performance, try firebase functions.

I am still working the server and client.

Kallikratidas

unread,
Dec 30, 2019, 5:34:15 PM12/30/19
to DroidScript
Well, I just found that I could use the firebase admin to create the server.

In that case I cannot give you the client and server files.

I can just advice you what to do.

*Download and install nodejs in your computer.

*Go at the console of your firebase prpject.

*Click functions.

*Follow the instructions there.

*Then you can easily say in your index.js file (you will understand want I mean if you do the above) and write the code auth.listUsers(max).then(OnListResult);

And you can have access to all database because you are connected as admin.

Or you can also use the functions by uploading this file using firebase deploy command in nodejs.

I think you will find it difficult but you will make it.

I learned all this in some hours, so try it too.

(If you see in nodejs a logging error about the credential, you will need to go to firebase/your project/setting/General/Service accounts and create a new secret key. Follow the instructions there too and put the in your config Jason.)

I hope that helped!

Regards

MFBBSubEsp

unread,
Dec 30, 2019, 10:57:56 PM12/30/19
to DroidScript
Thanks a lot =), I have yet to see fully how this works but I will do as you said and hopefully I find the handle of this, I really like coding and Droidscript is awesome tool for that, just I always face same trouble, I tend to have issues learning how external things work with whatever the environment I use, like in this case firebase or in other scenario gamepad bluetooth or something thats not part of the tool you know.

As said I will do all you dewscribed and let you know if any obstacle makes it not work (currently Im using emulator so Im a bit slow)

MFBBSubEsp

unread,
Dec 31, 2019, 12:13:52 PM12/31/19
to DroidScript
Currently I failed at some step, I did everything and managed to install the firebase packages in the pc however after that and pasting all thats needed in the code then the executed code fails but as said Im sure I did a step wrong somewhere

I will keep retrying but really I thank you for the explanation and all the help, if you ever want to collaborate into an online project let me know, maybe I wouldnt be able to help in the online configuration etc but I can help in regular code and graphics, I did everything at mordazah.com just as a reference to show that im not someone who started coding yesterday, by the way if you have a gallery or site where we can play/buy your games that would be nice to see them so please let me know =)

MFBBSubEsp

unread,
Jan 2, 2020, 6:28:02 PM1/2/20
to DroidScript
Hi again, sorry to come over this but... are these steps valid if I work only using the Droidscript in a phone/tablet? somehow I thought that since Im installing the nodes program in pc and doing all these operations maybe its not right to do the code in a separate device, I know these operations are related to the database thats is of course in a server far away but just wonder as I saw a step somewhere (really its vrazy for me I dont know if it was in functions section at firebase site) that says to initialize the Firebase with some commands in the machine first

MFBBSubEsp

unread,
Jan 18, 2020, 11:07:21 PM1/18/20
to DroidScript
Hi again, Im sorry to come back with this stil not running, as said Im usually useless at running external things, well I think I followed your steps and even thouogh I include the firebase's app and analytics scripts at the beginning, I still get a error saying firebase is not defined, could you possibly share a simple script with all filed (except config I know this is personal), this way I think maybe I can try to see what Im missing. Im using everything from mobile edition, even the firebase site Im running all the configurations through mobile, I dont know if maybe I need a pc for something else considering you mentioned the nodes tool, well I hope you can help me clarify this, again Im sorry about delay, my phone has been knocked out for several days

Kallikratidas

unread,
Jan 27, 2020, 8:26:01 AM1/27/20
to DroidScript
Is the problem in the phone or the PC (server)?

If it is the phone just include the Firebase folder in your project.

Just like I did in the spks above.

MFBBSubEsp

unread,
Feb 3, 2020, 10:42:34 PM2/3/20
to DroidScript
Im very sorry about delay, several things kept me away from everything. Well now that i have my coding device back (i was using emulator meanwhile), i can describe more or less what i see not working here, i compile both of your clients programs and they can be run in Droidscript with no error, they say status is offline but i assume its correct as you said both have to be running at the same time, but if i build the apks they give me error on a lot of ">" token symbols that go like "anonymous" and some other code, when i run these apks they dont show same interface as they show black screen so i assume the error i got building both is what makes them not work. Aside from that i tried building my own code from zero based om firebase's code shown in their site and that doesnt even compile but of course that my fault as i dont fully understand what this code does. Im open to any suggestion

Kallikratidas

unread,
Feb 4, 2020, 2:32:23 PM2/4/20
to DroidScript
This is an existing problem with the Apk Builder that is being discussed in the beta forum

Try to unchecked the 'Obfuscate Code' option and build the Apk using debug.

Try it and tell me.
Check also the Apk of these two spks I had posted.

Kallikratidas

unread,
Feb 4, 2020, 2:46:14 PM2/4/20
to DroidScript

MFBBSubEsp

unread,
Feb 6, 2020, 8:46:02 AM2/6/20
to DroidScript
Sorry I couldnt reply earlier and again thanks a lot for the help, i tried as you suggested and you are right, unchecking the obfuscate code it built the apk the right way, however the version of your code i set with my database configuration remains offline but the apk you shared connects in the correct way and the messages are passed well, i might notice a small delay but because my internet is slow it surely causes that. So my guess is i configured something wrong at the firebase although it seems hard to do that...

Kallikratidas

unread,
Feb 6, 2020, 3:08:27 PM2/6/20
to DroidScript
I couldn't use your firebase config in these apks. I didn't know it. So I used one of mines.

Try to build the app your self to have access to this app from the firebase console.

MFBBSubEsp

unread,
Feb 8, 2020, 8:01:24 PM2/8/20
to DroidScript
Thanks again =), Im sorry to ask this but just to be sure I understood things right, to fully configure the firebase database should I do anything beyond going to the firebase site and follow the steps you describbed before? I mean as you mentioned nodejs program for the pc I wonder if I could have the database work just with the firebase site configuration and the describbed steps in the site, because your program clearly works fine with your configuration then I configured it wrongly so its either I missed a step or something and the config part is just a piece of code they give us and you kindly indicated where to add so it should be more complex at this level unless I understood it wrong and we need to do something else outside the firebase site to make the database work, I hope you can confirm this as I feel useless failing in something that looks simple

Kallikratidas

unread,
Feb 9, 2020, 2:30:18 AM2/9/20
to DroidScript
Well, I don't think it is that complex. Have you tried to use your firebase config were the sample spks say?

The firebase config can be found in the console.firebase.google.com

Open your project, go to settings,
Click add an other app, choose the WebApp option (DroidScript is like a WebView, that's why)
and coppy the code it will show you.
It is not needed to complete the 'Add Web App' operation. Just make this process to get your firebase config (not the SDK).

I would advice you not to use the firebase functions yet, because you are not ready. Forget the NodeJS for some time and try to understand how the firebase works.

Client-> makes a request.
Server-> answers this request.
Client-> receives the answer.

Eg.

Client-> Matchmake me.
Server-> {battleId}
Client-> Cancel my Matchmake.
Server-> //Ignore's it,battle has started.
Client->//Gets in the battle screen

When the server.js starts, mind that you must always reset the game states.
As I did the very beginning, you can
store the users data on a path named '/users' and a user would seem like '/users/{uid}'

To receive battle requests, create a folder '/battleReq'
and listen to it from the server.js
//db.ref('battleReq').on("value",BattleRequest);

As I said above, always reset all the states, by setting all user states to 'home' screen.

Eg.
/users/{uid}/state = "battle" -> /users/{uid}/state = "home";

I think you got a little piece of the server-client logic. Try to make a server and a client and tell me.

MFBBSubEsp

unread,
Feb 10, 2020, 9:06:55 PM2/10/20
to DroidScript
Well, Kallikratidas, thanks a lot again for your patience and explanations, I know I might sound like a totally unskilled person and in relation to this online field it seems so. Now about what happened, I did as you said, followed your steps, got the code and pasted in your example (I want first to have it run then see how it works and build my code etc), well as I paste it I get same error I got the first time you shared it with us, it says firebase is not defined but there is the Firebase folder you included with your code, so from that point Im lost, there are 2 lines that call firebase at start that are firebase.initializeApp and firebase.analytics, if I comment these lines the code compiles but remains offline always, I think this is probably the same that happened to me before but apparently I should include the firebase files somewhere, I see in the code provided at firebase site they call the 2 firebase js files from a certain url, but this is html (unless memory fails), so in my ignorance I think I should call or include these js in the code somewhere, as said you have the firebase folder but I dont know if this serves for the same thing or maybe Im totally lost.


These js I assume I should include them in the code or maybe not, well just a guess 
after a zillion attempts you know, sorry if my guess is senseless but Im sure you can explain
why this happens

Kallikratidas

unread,
Feb 11, 2020, 6:34:16 AM2/11/20
to DroidScript
Well, I don't understand were you really get stack.

Do the apks that I have shared work to you?

Try the following spks and tell me.
Try the v1 and if it doesn't work try the v2 and tell me. I have used me own firebaseConfig to make sure this will not a problem.

Kallikratidas

unread,
Feb 11, 2020, 6:36:11 AM2/11/20
to DroidScript
client 1 ver1.spk
client 2 ver1.spk

Kallikratidas

unread,
Feb 11, 2020, 7:57:19 AM2/11/20
to DroidScript
client 1 ver 2.spk
client 2 ver2.spk

MFBBSubEsp

unread,
Feb 11, 2020, 10:27:29 PM2/11/20
to DroidScript
Again thanks a lot for your help, well here is what happened, both of the versions of your 2 clients work perfectly, they connect and get hello message and send messages, well thats cool, seeing your code i think looks similar to the one i edited from your client, tried pasting my configuration in both of the versions clients and then they dont work, as said it has to be something in the configuration i guess... because i havent done anything but pasting the config from firebase (pasting cant go wrong! lol), in fact i know its pointless to show it but here is the config i pasted, i know nothing can be seen wrong here because its just ids and data given by site, well just in case:

var firebaseConfig = { apiKey: "AIzaSyB4pVOWzkgzk9XJJvXcw5tCQVyqBPYF_I4", authDomain: "fir-1st-e0c27.firebaseapp.com", databaseURL: "https://fir-1st-e0c27.firebaseio.com", projectId: "fir-1st-e0c27", storageBucket: "fir-1st-e0c27.appspot.com", messagingSenderId: "211188285343", appId: "1:211188285343:web:79133f5376fcb2903487aa", measurementId: "G-21CH0FCBXX" }; 

Kallikratidas

unread,
Feb 12, 2020, 8:58:03 AM2/12/20
to DroidScript
Not, it is not pointless at all because I think you have skipped 2 simple steps:

1)Make sure you have created a realtime database. If not make it!
(Important: RealTime Database, not File Cloudstore)

2)Go to the Authentication option and go to sign in methods. Enable only the Email one. (No gmail or anything else).

Try and tell me!

MFBBSubEsp

unread,
Feb 14, 2020, 12:12:50 AM2/14/20
to DroidScript
Awesome!! you are totally right, i cant tell for sure if i missed the 2 steps or just one but anyway i decided to make a new project and this time be sure i do all as you said and it worked :D, thanks a lot for your time and effort to make it work really, i know i have a long road ahead to know how to make everything but having this first test work is totally great =). I know you helped with the will to give a hand to someone totally stuck in something but i feel totally thankful and sorry for the trouble, do you mind if i send you a couple of things i made? Via email or well IM program/app, its the least i can do after all the trouble that i made and all the time you spent on this

Kallikratidas

unread,
Feb 14, 2020, 3:27:55 PM2/14/20
to DroidScript
Every trouble is understandable because you were introduced to something new, so it was my pleasure to help you. You can send me any kind of SPK or question you have here in the forum or to my email: nikola...@gmail.com . I am all ears to any kind of problem or anything else you have in order to help you make it.
Regards

MFBBSubEsp

unread,
Feb 14, 2020, 10:44:56 PM2/14/20
to DroidScript
Thanks a lot Kallikratidas, I will write you short email later, I tend to like to face my troubles alone and usually thats the case as I work alone almost always but when its something from "outside" the tool I usually have a rough time, I hope I dont need to ask you any other trouble here or there and hopefully I can deal my way at firebase with this great starting step you gave me =)

Maurizio R.

unread,
Apr 21, 2020, 4:12:03 PM4/21/20
to DroidScript
hi, I have read your messages and I understand that you have experience with firebase integration in droidscript, I wanted to ask you if I can integrate FCM cloud messages into a doidscript apk and if it is possible to elecarmi the various steps to be performed, if you have an easy example I would be very grateful to you, good continuation of the work, Maurizio

Kallikratidas

unread,
Apr 21, 2020, 5:11:45 PM4/21/20
to DroidScript
Have you checked the Google Firebase's Cloud Messaging documentantion?

https://firebase.google.com/docs/cloud-messaging

Maurizio R.

unread,
Apr 23, 2020, 6:32:19 PM4/23/20
to DroidScript
I have used your files and descriptions and I have to congratulate you, for now I am connecting on your firebase db but when I insert my json file firebase config it is not authorized, can you give me some right information to have more luck? thanks and good job

Kallikratidas

unread,
Apr 25, 2020, 1:49:12 AM4/25/20
to DroidScript
If you have your firebase config json and it doesn't work, means maybe you haven't created a database yet. Go to your firebase project on the Firebase Console and click the Database from the list. Then create a Real Time Database not a File CloudStore. Try this and tell me.

Kallikratidas

unread,
Apr 25, 2020, 1:52:01 AM4/25/20
to DroidScript
And of course set the database rules to test, because you won't have access to it if you have the writing option to false or the reading. Always use the Test Mode. After you get experienced with it you will be able to use and security for hackers and cheaters, but as a headstart, don't.

Regards

Reply all
Reply to author
Forward
0 new messages