Whats needed next
-
- Posts: 24
- Joined: Tue Oct 20, 2009 3:00 pm
Re: Whats needed next
I have seen the gold video, but it only has the same layouts as the top. :/
-
- Posts: 25
- Joined: Mon Mar 15, 2010 8:27 pm
Re: Whats needed next
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);
}
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);
}
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Whats needed next
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.
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.
The indelible lord of tl;dr
-
- Posts: 25
- Joined: Mon Mar 15, 2010 8:27 pm
Re: Whats needed next
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.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.
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Whats needed next
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 

The indelible lord of tl;dr
-
- Posts: 25
- Joined: Mon Mar 15, 2010 8:27 pm
Re: Whats needed next
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?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
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Whats needed next
Code: Select all
total=<?php echo"$gold"?>;
Code: Select all
var total=<?php echo"$gold"?>;
-
- Posts: 25
- Joined: Mon Mar 15, 2010 8:27 pm
Re: Whats needed next
hallsofvallhalla wrote:should beCode: Select all
total=<?php echo"$gold"?>;
matter of fact you are missing quite a few vars, all js variables must be defined first using var...Code: Select all
var total=<?php echo"$gold"?>;
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?
-
- Posts: 175
- Joined: Sun Oct 11, 2009 9:33 am
Re: Whats needed next
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.

So before saying it won't work, give it a try.
-
- Posts: 25
- Joined: Mon Mar 15, 2010 8:27 pm