Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
So I've been playing around with the code for this: [url]http://madebyevan.com/webgl-path-tracing/[/url]
[img]https://lh5.googleusercontent.com/-3KyJllqURl8/UVFAgpNhi3I/AAAAAAAAJnA/_6uW2Mm33sQ/s0/2013-03-26_02-30-24.png[/img]
and it's been a lot of fun, but I decided to try to add WASD navigation and I've gotten stuck.
At the very bottom of webgl-path-tracing.js is room to add hooks for input, with the only ones already in the script for backspace/delete for deleting objects. Adding forwards and backwards was easy to do in a hacky way
[code]if(event.keyCode == 87) {
zoomZ -= 0.01;
ui.renderer.pathTracer.sampleCount = 0;
}
if(event.keyCode == 83) {
zoomZ += 0.01;
ui.renderer.pathTracer.sampleCount = 0;
}[/code]
which just moves the camera closer/further from the center of the scene, which works because the camera is always facing that direction anyways. However, I can't seem to reposition the camera (he calls it "eye"), and throwing vector operations at it isn't getting anywhere. Anyone else want to have a look?
Anyone know of any tutorials(for a newbie) for submitting text through a text box and having it displayed on the page in an array?(and if text is submitted again it will create a second entry in the array etc.)
Thanks for any help
Do any of you know any great lightweight blogging software?
I'm trying to make a portfolio site that includes most of the stuff that I've made and a small blog.
I honestly don't want something as big as wordpress etc.
How do I use Socket.io? Does my web server need to have node.js installed?
I want to write a chat client that uses websockets but apparently websockets requires some sort of special handshake so I can't just connect to my own TCP server(that runs on a dedicated machine, such as my windows box) and relay information back and forth.
[QUOTE=false prophet;40068389]How do I use Socket.io? Does my web server need to have node.js installed?
I want to write a chat client that uses websockets but apparently websockets requires some sort of special handshake so I can't just connect to my own TCP server(that runs on a dedicated machine, such as my windows box) and relay information back and forth.[/QUOTE]
You can host the websocket stuff on another port so you don't have to worry about redoing a lot of your code.
As for the websocket stuff you will need a websocket server. You can use Node.Js for that etc. I prefer the python-websocket module becuase it hooks into django and cherrypy.
[url]https://github.com/Lawouach/WebSocket-for-Python[/url]
Right so basically I have a function that sends a query to my GMod servers to get information such as hostname, map, player count and max players et cetera. What I want to do with this is place the information into a separate Array and return the value, so I can use it to produce a HTML Table. This is my current code:
[php]function query($serverip)
{
$query = query_source($serverip);
$percentage = round($query['players'] / $query['playersmax'], 2) * 100;
echo "Name: ".$query['name']."<br>";
echo "Map: ".$query['map']."<br>";
echo "Percentage: $percentage%<br>";
echo "Players: ".$query['players']."/".$query['playersmax']."<p>";
}
$servers = array(
"87.117.217.152:27015",
"87.117.217.107:27015",
);
for($i=0;$i < count($servers);$i++)
{
query($servers[$i]);
}[/php]
Now this works well on producing the output I want, but I want to put it into a table I have an idea that using two-dimensional arrays would work but I don't know how to implement it into the function, this is something I thought would work but it doesn't.
[php]
function query($serverip, $returned)
{
$query = query_source($serverip);
$percentage = round($query['players'] / $query['playersmax'], 2) * 100;
echo "Name: ".$query['name']."<br>";
echo "Map: ".$query['map']."<br>";
echo "Percentage: $percentage%<br>";
echo "Players: ".$query['players']."/".$query['playersmax']."<p>";
$returned[1] = $query['name'];
return $returned;
}
$servers = array(
"87.117.217.152:27015",
"87.117.217.107:27015",
);
$outputted = array(
array("TTT"),
);
for($i=0;$i < count($servers);$i++)
{
query($servers[$i], $outputted[$i]);
}[/php]
What I thought it would do is return the Array so I could use $outputted[0][1] to be able to output the hostname, ehm.. Here is the code that I thought would work. I'm a complete newb at PHP and this is essentially my first programming language that I'd like to learn and this would help a lot, so if somebody could help that would be appreciated.
I'm guessing that this is what you want to achieve:
[PHP]
$servers = array(
"87.117.217.152:27015",
"87.117.217.107:27015",
);
foreach($servers as $server){
$data = query_source($server);
$percentage = round($data['players'] / $data['playersmax'], 2) * 100;
echo '<tr>';
echo '<td>'.$query['name'].'</td>';
echo '<td>'.$query['map'].'</td>';
echo '<td>'.$percentage.'%</td>';
echo '<td>'.$query['players'].'/'.$query['playersmax'].'</td>';
echo '</tr>'
}
[/PHP]
If you just want an array:
[PHP]
$servers = array(
"87.117.217.152:27015",
"87.117.217.107:27015",
);
$array = array();
foreach($servers as $server){
$array[$server] = query_source($server);
$array[$server]['percentage'] = round($data['players'] / $data['playersmax'], 2) * 100;
}
[/PHP]
Then you can just access things like $array['87.117.217.107:27015']['percentage'].
Also if you do fill an array with data first you can build the HTML the nice way:
[PHP]
<table>
<tr>
<th>IP</th>
<th>Name</th>
<th>Map</th>
<th>Percentage Full</th>
<th>Players</th>
</tr>
<?php foreach($array as $key => $item): ?>
<tr>
<td><?php echo $key ?></td>
<td><?php echo $item['name'] ?></td>
<td><?php echo $item['map'] ?></td>
<td><?php echo $item['percentage'] ?>%</td>
<td><?php echo $item['players'].'/'.$item['playersmax'] ?></td>
</tr>
<?php endforeach; ?>
</table>
[/PHP]
Edit: Just to note that I've not tested it.
Im trying to learn AJAX, jQuery and JavaScript. I've hit a wall.
I'm trying to make a non-refresh form.
Heres my form.
[CODE] <div class="msgbox"><?php echo output_errors($errors);?></div>
<div class='finput'>
Username: <input type="text" name="username" id="username" class='finputb'>
</div>
<div class='finput'>
<a href="#" onclick="changeUsername()" class="btn" value="Change Username!">Next</a>
</div>
[/CODE]
Then i have in my nav.js
[CODE]
function changeUsername() {
$.post('change_username.php'), {username: $('#username').val()}, function(data) {
}
$("#right").fadeOut();
}[/CODE]
I am not sure if i am heading in the right direction, i want them to click submit, if error .fadein() an error box, if successful it will .fadein() a success box and update the mysql.
Anyone have any ideas as to how I could spawn a SRCDS (source dedi server) process with PHP - and keep it up?
[editline]30th March 2013[/editline]
On Windows, mind you
I've had a Dreamhost server for awhile but I never did anything with it but use it as an SVN repository. I'd like to turn it into a private image hosting service where I can upload images to a repository, viewable only by me unless images are directly linked. Preferably the uploading could be done without using an FTP client (i.e. through a browser). It doesn't have to be fancy with tagging or rating or comments or shit, simplicity is preferred.
How can I go about doing this?
[QUOTE=Knallex;40089080]Anyone have any ideas as to how I could spawn a SRCDS (source dedi server) process with PHP - and keep it up?
[editline]30th March 2013[/editline]
On Windows, mind you[/QUOTE]
There's always system() or exec() if you really want to...
[QUOTE=Ac!dL3ak;40094040]There's always system() or exec() if you really want to...[/QUOTE]
The problem with them on their own is that it will wait for srcds to 'finish' before it can carry on with the PHP script.
[QUOTE=CBastard;40094285]The problem with them on their own is that it will wait for srcds to 'finish' before it can carry on with the PHP script.[/QUOTE]
Don't they have flags so they don't do that? Like .NET's Process class has something for not waiting the processes end. Might have to spin a thread.
[QUOTE=CBastard;40094285]The problem with them on their own is that it will wait for srcds to 'finish' before it can carry on with the PHP script.[/QUOTE]
Just use popen() without calling pclose(), I guess
I'll give your suggestions a try, if they don't work, I heard something about using "psexec.exe" together with exec() should work, thanks!
-snip-
[QUOTE=Knallex;40098903]I'll give your suggestions a try, if they don't work, I heard something about using "psexec.exe" together with exec() should work, thanks![/QUOTE]
I was looking through some of my old code and found:
[PHP]pclose(popen("start ". $cmd, "r")); [/PHP]
$cmd being the path to the executable.
[QUOTE=CBastard;40099888]I was looking through some of my old code and found:
[PHP]pclose(popen("start ". $cmd, "r")); [/PHP]
$cmd being the path to the executable.[/QUOTE]
Does this fork the process so PHP doesn't wait for it to close, too?
[QUOTE=Knallex;40099990]Does this fork the process so PHP doesn't wait for it to close, too?[/QUOTE]
I believe so yes.
[QUOTE=Knallex;40099990]Does this fork the process so PHP doesn't wait for it to close, too?[/QUOTE]
[QUOTE=CBastard;40100013]I believe so yes.[/QUOTE]
No, it doesn't. pclose() has to wait for the process to exit before it can return a termination status.
[editline]30th March 2013[/editline]
That's why I recommended not calling pclose() at all.
[QUOTE=Ac!dL3ak;40100236]No, it doesn't. pclose() has to wait for the process to exit before it can return a termination status.[/QUOTE]
I just tested it (windows) and it worked for me, it did open the program with the system account though so it was running in the background.
If anyone here knows anything to do with coffeescript, how would I get the following code working?
[code]
class @Resources
@images = {}
@image_total = 0
Load: (file_list) =>
$.getJSON file_list, (asset_list) ->
#Load the images
for key, value of asset_list.images
@Test();
Test: =>
alert "ha"
[/code]
As the function "Test" doesn't appear in the scope of that $.getJSON request.
[QUOTE=AzzyMaster;40107453]If anyone here knows anything to do with coffeescript, how would I get the following code working?
[code]
class @Resources
@images = {}
@image_total = 0
Load: (file_list) =>
$.getJSON file_list, (asset_list) ->
#Load the images
for key, value of asset_list.images
@Test();
Test: =>
alert "ha"
[/code]
As the function "Test" doesn't appear in the scope of that $.getJSON request.[/QUOTE]
[code]
class @Resources
@images = {}
@image_total = 0
Load: (file_list) =>
$.getJSON file_list, (asset_list) =>
#Load the images
for key, value of asset_list.images
@Test();
Test: =>
alert "ha"
[/code]
the "fat" arrow makes sure to keep `this` in the inner context as the outer context by binding `this` to another variable upon compilation
[QUOTE=Ac!dL3ak;40107485][code]
class @Resources
@images = {}
@image_total = 0
Load: (file_list) =>
$.getJSON file_list, (asset_list) =>
#Load the images
for key, value of asset_list.images
@Test();
Test: =>
alert "ha"
[/code]
the "fat" arrow makes sure to keep `this` in the inner context as the outer context by binding `this` to another variable upon compilation[/QUOTE]
Thanks, I knew I had to be doing something stupid.
[QUOTE=boshuajackman;40084619]
I'm trying to make a non-refresh form.
i want them to click submit, if error .fadein() an error box, if successful it will .fadein() a success box and update the mysql.[/QUOTE]
What you want is called validation.
[QUOTE=boshuajackman;40084619]
I am not sure if i am heading in the right direction, i want them to click submit, if error .fadein() an error box, if successful it will .fadein() a success box,[b] validate serverside [/b]and update the mysql.[/QUOTE]
FTFY ...Unless you wanted injection, fake data or just left out that part.
I'm starting to get a little annoyed I can't figure this out.
I'm trying to make a news system, but can't get the divs to play nice.
All I'm trying to do is a design like this:
[......Title Bar......]
[PIC][News.........]
[.....][.................]
[....Date Stamp....]
Title bar, two divs side by side that extend downward together as news is longer, and a bottom bar.
I can do it in a table with colspan=2 but I'd like to stay away from tables since their customization isn't quite on par with divs.
[QUOTE=mrgrim333;40120587]I'm starting to get a little annoyed I can't figure this out.
I'm trying to make a news system, but can't get the divs to play nice.[/QUOTE]
Post code.
With this, the setup looks right except the pic div doesn't extend down to the date bar.
[lua]<div style="width:600px; background-color:red;">
<div style="width:100%; background-color:orange;">
Title
</div>
<div style="width:100px; min-height:100px; background-color:yellow; float:left;">
pic
</div>
<div style="width:500px; background-color:green; min-height:100px; float:left;">
News Body<BR>a<BR>b<BR>c<BR>d<BR>e<BR>f<BR>g
</div>
<div style="width:600px; background-color:blue;">
Date stamp
</div>
</div>[/lua]
[QUOTE=mrgrim333;40122892]With this, the setup looks right except the pic div doesn't extend down to the date bar.
[lua]<div style="width:600px; background-color:red;">
<div style="width:100%; background-color:orange;">
Title
</div>
<div style="width:100px; min-height:100px; background-color:yellow; float:left;">
pic
</div>
<div style="width:500px; background-color:green; min-height:100px; float:left;">
News Body<BR>a<BR>b<BR>c<BR>d<BR>e<BR>f<BR>g
</div>
<div style="width:600px; background-color:blue;">
Date stamp
</div>
</div>[/lua][/QUOTE]
I cleaned up your code a bit.
[url]http://jsfiddle.net/HSgnJ/3/[/url]
Don't use inline css. It's a bad practice because it's harder to maintain a site.
Sorry, you need to Log In to post a reply to this thread.