A few questions

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

A few questions

Post by Epiales »

Hello all...

Just wanted to say what a great site this is. YAY! Glad I found it. One question I have though, is that through all the videos I've watched, there isn't any that show how to have your attacks show up in another div break on the same page as where it updates your stats.

I've piddled around a lot with this recently and can't figure anything out. When you attack, it goes to attack.php, and then your return. That makes it hard to use, let's say, an Iframe so that players can see their information immediately. If you use an Iframe, it allows them to see the attack and the points, but it won't refresh their stats on their main page unless they refresh the entire page. I"m sure there is a way to do this, but haven't found a way around it. Same problem when they go to level up. Using an Iframe doesn't work well with that. As they would have to scroll down the frame in order to put their points on their stats. I personally hate frames lol. Also, is there anything about storing their currency, be it credits, gold, or anything else, in a bank? Thanks for reading my book of a message :)

Anyone have any ideas, or at least, point me in the right direction so that I can study more on this?

Thanks again,

X
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: A few questions

Post by Jackolantern »

What you are describing about the refresh is the way that PHP works (and all other server-side languages). The entire structure of PHP is based around a request coming in, running some code to generate HTML and sending that back to the browser to display. Within PHP, there is no way around that. However, Javascript and the entire concept of client-side scripting is how you make things happen in the browser without refreshing the page. The Browser MMORPG tutorial does not go into Javascript, as you should really have a firm grasp on HTML and server-side scripting in PHP before expanding out to client-side scripting. Javascript is how virtually all websites today have effects and do things without a page refresh. Everything from animated effects when you mouse-over a button to full-on animated games and chat rooms are done with Javascript. Using AJAX or WebSocket techniques can even allow you to get data from the server and database without refreshing the page.

I would suggest to focus on the PHP for now, and once you feel comfortable with that (after playing around for a while after doing the MMORPG tutorial), you can move on to learning Javascript through the tutorial series we have here and other resources. At that point everything will just "click", and you will suddenly see how you can make almost anything you want to on the web.

As for banks, I am not sure but I believe they are introduced later on in the series :cool:
The indelible lord of tl;dr
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: A few questions

Post by Epiales »

Thanks for the info...

I have started my game YAY! One thing I"m having trouble with right now is a countdown for like a troop. I mean, if you go and train a troop, I want it to be like 10 minutes before that troop becomes available. I have searched and searched online for awhile now, so that I wouldn't bother anyone here with questions. I'm really trying to do most on my own. I'm not asking for code to be written for me, but a point in the right direction. Anything would be helpful. Thank you.

X
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: A few questions

Post by MikuzA »

As the answer for your both first and latest questions, you could go for HTML/PHP combined with JavaScript. In more precision, AJAX.
With help of Ajax, you can create more interactive content to your game.

Or if you feel confused right now, jQuery would be where to start with that, it's an JavaScript library which have all kinds of neat stuff added to it. And their page itself has some tutorials you might just copypaste and modify to your own needs.

That's just pointing out that it's possible with not that much of 'learning', even thou I would definetly suggest doing some learning on PHP, since that's the language that does/should do all the 'magic'. Logics and data updates at least.

That's my two cents.

So,
http://www.w3schools.com/ for HTML/CSS
http://jquery.com/ for jQuery
http://www.php.net/ for PHP function examples, note that if you don't know function you might require then google is your best buddie.


and hey, you can always ask for anything, here at least. We tend to push people forward with whatever we can offer.
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: A few questions

Post by Epiales »

Thanks MikuzA,

I know some about php/html, as years ago I did a lot of work with it. But I don't remember everything. Lots to remember :D

However, I don't know much about ajax or jquery. Thanks for the links. CSS is kind of new to me, but I've learned a ton on that just by watching video's here. Great site! Thank you. I'll do some reading on those links. Hopefully I can find out about the timers that I'm wanting. If not, I'll be back (Arnold Voice) :)

X
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: A few questions

Post by MikuzA »

As for the timer how to actually do this, I would suggest following.

have a button 'train/build', that initiates the timer. Save 'current unix timestamp' to database for 'training_init'.
Dependant on what you are training/bulding, you have an table created with contains all the durations/resources that training/building needs.
For example, 1 hour training time.

You have a gui that initiates a JavaScript count down on the (start_unix_timestamp + 60 minutes) - start_unix_timestamp = time_of_completion.
This time is reached from database with help of jQuery/Ajax, which from then you generate a 'countdown timer'.

And when countdown reaches zero you have jQuery/Ajax do another action, which then would for example +1 unit/building of that certain type. set the construction/training table data entry to 'completed' or add an completion time.

This would be my few cents on how to actully do it, but you might cross up a better way when you are digging into it :)
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: A few questions

Post by Epiales »

I've been doing some reading and looking on this. Is it possible to just have a timer upon clicking train? And then the train button would not be available until the times up? I don't know for sure, but have been lookin' around some. Only problem I would see with this is that upon page refresh, the timer would restart, unless there can be a session included in the script. Any idea?

X
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
Xaos
Posts: 940
Joined: Wed Jan 11, 2012 4:01 am

Re: A few questions

Post by Xaos »

Epiales wrote:I've been doing some reading and looking on this. Is it possible to just have a timer upon clicking train? And then the train button would not be available until the times up? I don't know for sure, but have been lookin' around some. Only problem I would see with this is that upon page refresh, the timer would restart, unless there can be a session included in the script. Any idea?

X
Could do something like set the timer and have something like if(timer > 0){ display timer time left } elseif(timer = 0){ display train }

Or have a verification when you click train. Ie you click train, get a JS popup with how much time you have left or the result of training. Basically throw an error if the timer isn't 0
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: A few questions

Post by Jackolantern »

This may have mentioned and I may have missed it, but client-side Javascript timers are just a convenience for the user, and are not reliable. The actual mechanism to keep users from jumping the timer and skipping the countdown has to be done on the server-side. Anytime a client-side timer is used for various uses (such as those now found on many file downloading sites), it is only a day or so before someone realizes it is only client-side and builds something to tamper with the JS and count it instantly down to 0.

As far as the actual mechanism, this would likely be the best way to do it: Once the action is triggered on the server, do what Mikuza said and have a timestamp on a MySQL column so that you save the exact time it started. Then you can start a JS timer on the client with the full amount of the countdown. If the page is refreshed, the PHP script can hit the db and see if the user is waiting on a timer. If they are, trigger a JS timer to appear that displays the time left and begins counting down (make sure this part of the code reacts correctly and does not display the timer if they are not waiting on a timer, since it would be the same script run the first time they visit the page). It will likely be off by around a second or two for transmission and rendering time, but its not important.

Having a db entry to keep track of the timer is the best way to handle it, since MySQL has a very handy timestamp column type, as well as nice datetime functionality.

EDIT: This thread contains some info about using timestamps and making decisions based on that. The main difference was the time scale was in days there, whereas you will be using minutes most likely here.
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”