PUBLIC FORUMS/GENERAL FORUM

Topic Title: Coding help (Simple Topic)

Topic starter: justanius

Topic started: 22:56:06 22nd Jan 2011

Posts: 10 Last post: 00:28:38 31st Jan 2011 by justanius

justanius Posted: 22:56:06 22nd Jan 2011

Posts: 37

Topics: 9

Location: United States

Gender: Male



I'm having a major brain fart right now. I haven't done much coding in the last year (and I'm also not much of a mathematician). I'm trying to write a script that will calculate the distance between an object and a destination

This is written in PHP by the way.


$xd = ($object['x]) - ($destination['x']);
$yd = ($object['y]) - ($destination['y']);
$zd = ($object['z]) - ($destination['z']);

//Sqrt is a square root function, and pow($xd, 2) is $xd squared.

$distance = Sqrt((pow($xd, 2))+(pow($yd, 2))+(pow($zd, 2)));

Not sure what I'm doing wrong. I honestly don't think anything is wrong with my math. I'm getting a different number than what shows up on the I-flight page.




__________________________
AKA DRD, ED... and some other names I can't think of at the moment

Marvel Magnum Posted: 23:54:08 22nd Jan 2011

Posts: 330

Topics: 27

Location: Canada

Gender: Male



I don't know PHP but the math looks ok. (Maybe if it was C++, I could have helped ... )




__________________________
"Marvel is my name, Marvellous is thy game."

Moiare Posted: 10:55:33 23rd Jan 2011

Posts: 135

Topics: 6

Location: United States

Gender: Male



My PHP is rusty too, but are you missing some single quotes in the $object[ ] ?

$xd = ($object['x']) - ($destination['x']);
$yd = ($object['y']) - ($destination['y']);
$zd = ($object['z']) - ($destination['z']);




__________________________
Give a man a fire and he's warm for a day, but set fire to him and he's warm for the rest of his life.

If you build it, they will complain.

justanius Posted: 07:22:45 24th Jan 2011

Posts: 37

Topics: 9

Location: United States

Gender: Male



Oh no, I'm not I just changed them to make them more easily readable.

I think either I'm missing something or SL's math isn't correct. dunno.




__________________________
AKA DRD, ED... and some other names I can't think of at the moment

Exemplary Strategy Posted: 00:14:16 25th Jan 2011

Posts: 928

Topics: 47

Location: United States

Gender: Male



what is the point, all you do is, +number to -number, in each area, and add the numbers.. so
13000:-5000:15600
-2456:-4590:-31005
13000+2456 + 1 is the space in first section
because the middle are both - instead of one of each, it's 410 higher number away from lower number,
third section, add the numbers 15600 and 31005 and 1.
add those, three distances, and you have the total. just make a calculator exactly that way, and you cant mess the math up.




__________________________
We have wings on our backs and we have horns on our heads, our fangs are sharp and our eyes are red, we're not quite demons or the one that fell, so choose to join us or go straight to hell!

Loyal as any dog.

Exemplary Strategy Posted: 00:17:40 25th Jan 2011

Posts: 928

Topics: 47

Location: United States

Gender: Male



im trying to do the if for the calculation, but i know NO php, so dont be mad if you have to help me, btw, will people hit me up on msn frotobagginses@hotmail.com, if you think you can help. i'll show you what i have so far.




__________________________
We have wings on our backs and we have horns on our heads, our fangs are sharp and our eyes are red, we're not quite demons or the one that fell, so choose to join us or go straight to hell!

Loyal as any dog.

Exemplary Strategy Posted: 00:38:08 25th Jan 2011

Posts: 928

Topics: 47

Location: United States

Gender: Male



<form method="get" action="action.php">

Enter the first coordinate First section <input type="text" name="number1">
Enter the first coordinate Second Section <input type="text" name="number2">
Enter the first coordinate Third section <input type="text" name="number3">
Enter the second coordinate First section <input type="text" name="number4">
Enter the second coordinate Second Section <input type="text" name="number5">
Enter the second coordinate Third section <input type="text" name="number6">
Parsec Calculator <input type="radio" name="op" value="dis">
submit <input type="submit" name="Submit" value="Submit">

<?php

if ( $op == "dis" ) {
echo "$number1 + $number4 = ";
echo $number1 + $number4;
echo "$number2 + $number5 = ";
echo $number2 + $number5;
echo "$number3 + $number6 = ";
echo $number3 + $number6;
}

?>




__________________________
We have wings on our backs and we have horns on our heads, our fangs are sharp and our eyes are red, we're not quite demons or the one that fell, so choose to join us or go straight to hell!

Loyal as any dog.

Exemplary Strategy Posted: 00:39:46 25th Jan 2011

Posts: 928

Topics: 47

Location: United States

Gender: Male



im sure you can tell i dont know php from this, but if it helps, use it.




__________________________
We have wings on our backs and we have horns on our heads, our fangs are sharp and our eyes are red, we're not quite demons or the one that fell, so choose to join us or go straight to hell!

Loyal as any dog.

Exemplary Strategy Posted: 00:54:57 25th Jan 2011

Posts: 928

Topics: 47

Location: United States

Gender: Male



the if statement i need help with, is a negative value checker, the problem is, i dont know how to do the math, i can do it without a calculator, making one for me is pointless, but, if someone wants it, that's a Great reason to make it.
so i was trying to figure it out, i googled it, and found something to test negative. i dont know how to edit it to fit this code i submitted a few minutes ago.


function change()
{
var temp = document.calculator.text.value;

if (temp.substring(0,1) == "-" )
{document.calculator.list.value = "";
document.calculator.text.value = 0 - document.calculator.text.value * 1}

if (temp.substring(0,1) != "-" )
{document.calculator.list.value ="";
document.calculator.text.value = "-" + temp.substring(0,temp.length)}
}
this statement, despite it not fitting file names, functions as such, if the number is negative, it changes it to positive.. which is what i want in negative numbers in the calculator, because it makes it simpler to calculate the distance total. say -1000 and 1000 are the distances, logic says, it's 2000 spaces, (gave up on counting 0) the calculator, would = them out to 0, because it's not using logic, it's using general math.
now, if both numbers are 5000 and 5064 for example, it would need an entirely different function, because adding those up would obviously = 10064 instead of 64.
someone teach me how to do this, it's gonna bug me forever :(




__________________________
We have wings on our backs and we have horns on our heads, our fangs are sharp and our eyes are red, we're not quite demons or the one that fell, so choose to join us or go straight to hell!

Loyal as any dog.

H911Reiver Posted: 02:02:31 27th Jan 2011

Posts: 1939

Topics: 44

Location: United States

Gender: Male



err, 1000 - (-1000) = 2000

you shouldn't have any mathematical issues like that, logic says it's 2000 spaces and math agrees




__________________________
Now with 93% less edge and teenage angst

justanius Posted: 00:28:38 31st Jan 2011

Posts: 37

Topics: 9

Location: United States

Gender: Male



Yea, but that would just be making it too easy on myself. haha




__________________________
AKA DRD, ED... and some other names I can't think of at the moment

Previous 1  Next

© SkyLords 2002-2024 | SkyLords™ is Trademark worldwide | Terms of Use | Privacy Statement | Contact Us | Game FAQ
PUBLIC FORUMS
TICKETS
LANGUAGE FORUMS
SKYLORDS CHAT