Page 9 of 10
Re: Whats needed next
Posted: Wed Jan 06, 2010 2:08 pm
by RolsenRoyce
I have seen the gold video, but it only has the same layouts as the top. :/
Re: Whats needed next
Posted: Tue Mar 23, 2010 7:24 pm
by seanoseanohay
I am going to make a tutorial suggestion on something I am trying to figure out. I am actively studying it as well so please don't let me seem needy.
But how about something on putting php into action in a javascript. I keep finding this frustrating but maybe soon it will start to click what I am doing wrong. Here is an very rough draft where I have a javascript that runs on a time but it needs to pull the original data from a table using php...btw $gold is defined in the php part
<script type="text/javascript">
total=<?php echo"$gold"?>;
bank=1;
begintime=new Date();
function startTime()
{
var now= new Date();
now=Math.round((now%begintime)/1000);
diff = now%begintime;
begintime=new Date()
document.getElementById('txt').innerHTML=total+ " gold";
total = total +diff*bank;
t=setTimeout('startTime()',1000);
}
Re: Whats needed next
Posted: Wed Mar 24, 2010 3:43 am
by Jackolantern
You mean you need to learn about AJAX, where the Javascript queries the server to run a PHP script? I believe Halls is working on something like that for the future. If that is not it, what do you mean?
EDIT: Ohh, I see what you mean. How about this: When you load the page, why not have the PHP script pull the gold amount from the database and then write the amount into an invisible field that Javascript will then be able to act on like any other field? However, that is not a dynamic solution. The amount of gold in the invisible field that JS will be using will be the same until the page is reloaded. However, without using AJAX or allowing other players to take money from another player, that solution would be fine since you would only be using PHP to change the player's gold amount. However, if you do need the gold amount field to dynamic reflect the database value, it will have to be with AJAX.
Re: Whats needed next
Posted: Wed Mar 24, 2010 3:27 pm
by seanoseanohay
Jackolantern wrote:You mean you need to learn about AJAX, where the Javascript queries the server to run a PHP script? I believe Halls is working on something like that for the future. If that is not it, what do you mean?
EDIT: Ohh, I see what you mean. How about this: When you load the page, why not have the PHP script pull the gold amount from the database and then write the amount into an invisible field that Javascript will then be able to act on like any other field? However, that is not a dynamic solution. The amount of gold in the invisible field that JS will be using will be the same until the page is reloaded. However, without using AJAX or allowing other players to take money from another player, that solution would be fine since you would only be using PHP to change the player's gold amount. However, if you do need the gold amount field to dynamic reflect the database value, it will have to be with AJAX.
I suppose that is what I mean. I think part of my problem is not knowing how to use php and javascript together. Even what I wrote in this code would not display the value in $gold.
Re: Whats needed next
Posted: Thu Mar 25, 2010 11:25 am
by Jackolantern
Well, another way to do it would be to have PHP directly generate the Javascript. What the PHP interpreter spits out is nothing more than a standard HTML file, and as far as the server is concerned, Javascript is part of a standard HTML file

Re: Whats needed next
Posted: Fri Mar 26, 2010 7:52 pm
by seanoseanohay
Jackolantern wrote:Well, another way to do it would be to have PHP directly generate the Javascript. What the PHP interpreter spits out is nothing more than a standard HTML file, and as far as the server is concerned, Javascript is part of a standard HTML file

Right, that was what I originally wanted to do. But, I didn't know if it was possible to keep updating the resource amount without constanly refreshing the webpage. Here is a really simple version of what I mean.
http://home.csumb.edu/k/keenerlawrence/ ... w/test.jsp Is that possible if I just echoed all of my javascript code?
Re: Whats needed next
Posted: Sat Mar 27, 2010 4:41 am
by hallsofvallhalla
should be
matter of fact you are missing quite a few vars, all js variables must be defined first using var...
Re: Whats needed next
Posted: Sat Mar 27, 2010 7:37 pm
by seanoseanohay
hallsofvallhalla wrote:
should be
matter of fact you are missing quite a few vars, all js variables must be defined first using var...
Please do not take this sarcasticly. Does it really matter if the variables are declared? I mean doesn't js run like python where if you say gold = 5 then it will automatically make gold a variable? Will it actually affect the running of the script or is it just good coding practice?
Re: Whats needed next
Posted: Sat Mar 27, 2010 11:19 pm
by alexrules01
I think variables have to be declared, as Halls said in his NEW TUTORIALS OF URBAN REALMS (cheap plug

)!
So before saying it won't work, give it a try.
Re: Whats needed next
Posted: Sun Mar 28, 2010 12:29 am
by seanoseanohay