Jump to content

A battle script...


Snooble

Recommended Posts

Hey,

 

I'm working on a battle script to use... I have all the stats in variables pulled from a mysql db... but i want to reveal the fight one turn at a time...

 

the easiest way of doing this? Im guessing is to while(hp > 0) create an array with each turn in it turns['0'] etc... but how can i reveal them one by one to the user? javascript?

 

Thanks ever so much

 

Sam

Link to comment
Share on other sites

ok, i want to create a battle that the user can view...

 

$name = user1

$hp = 10

$min = 1

$max = 3

 

$name2 = user2

$hp2 = 40

$min = 5

$max = 7

 

Every turn user one will deal between 1 and 3 damage (eg. rand(1, 3)) my script needs to output:

 

Your weapon done rand(1,3) damage to $name2

 

then it should output name2's attack:

 

$name2's weapon did rand(5,7) damage to you

 

it needs to continue the loop untill someones hp goes beneath zero.

 

i need to output each turn eg(user does random damage) one at a time with a 3 sec delay between posting the info the the user.

 

hope that clears it up...?

 

 

thanks in advance lemmin

 

Sam

 

 

Link to comment
Share on other sites

So the user doesn't actually have to do anything for each turn? I guess you just keep loading the same page. That page checks a db for whose turn it is and last damage done, probably. You will probably have to refresh the page a couple times without the turn having changed since you don't have any event handlers in PHP. Do you get what I am trying to say?

Link to comment
Share on other sites

ok, so where would i be looking in javascript? to refresh every so many seconds...

 

see i was thinking that the fight would all be done in one process... and each turn put into an array...

 

user1()

 

user2()

 

but how can i get javascript to output each line of the array and how do i put each turn into an array?

 

thanks (sorry for all the questions)

 

Sam

Link to comment
Share on other sites

as revraz suggested, the easiest solution would be to do all of the turns in one process on the server and print out to the users the results of the different turns.

but how can i get javascript to output each line of the array and how do i put each turn into an array?

 

The set_timeout("function", x) function will wait x milliseconds and then execute the function (I think. I can't seem to find the documentation for this. Someone correct me if I am wrong.).

Your function would be something like top.location="page.php"; so that it keeps refreshing at certain intervals.

Or you can send a header with Refresh: 3 in your php

Link to comment
Share on other sites

The thing is, the reason i'd say javascript is because i dont mind the content to be on the page to start with (in the source)...

 

and then javascript (if im right) can output the information without refreshing the page?...

 

but (if you dont know javascript) could you help me work out a

 

while($hp > 0){

put information into an array?

}

 

just how would i increment the array... so each line equals a number in the array.

 

thanks people

 

Sam

Link to comment
Share on other sites

You can do something like this to instantiate your array in javascript. (The \0 is so that the extra comma at the end doesn't give a syntax error, but there are other ways around this.)

echo "<script language=\"Javascript\">var nums = new Array (";
while ($row = mysql_fetch_array($qry))
   echo $row['value'] . ",";
echo "\0);</script>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.