Jump to content

Need A Script


Goweigus
 Share

Recommended Posts

Getting a basic understanding of HTML and java-script (very basic) and am trying to make a simple online gamebasically works the same way that Brad the Game works (some text to read and several choice to make that lead to more text)this is what a page looks like basically, I haven't quite refined the writing yet (I can do better :)), but here is what I am hoping someone can give me:I would like a script (or whatever) that so when I push some a button, instead of it leading directly to 1 other file it determines based on a % chance i input that it loads 1 file out of several. So say the house is burning down and you can choose between fleeing, saving your pets, and getting valuables. Choosing to save your pets has say a 25% chance of loading the html file about how you made the wrong choice and died an agonizing deathI am quite a newb to all of this and am doing most of this by simply copying and pasting and saving whole new files for each choice made, I would like for some random chances/risk taking to be inalso: extra credit points (lol) for anyone that can give me a script that makes it so you can't press the back button and simply try again (if you mess up you have to start allllll over again) *not sure if thats even possible*Thanks for reading, and if i am out of line in anyway please direct me to where i can go (i wasn't able to find any place where newbs can just ask whatever they want)PS: if anyone knows how to do this for powerpoint/impress that would be super! *(can you put javascripts/custom scripts in those?)*<html><body><body bgcolor="Black"><!--Thanks to Brad the Game for inspiration and some html help--><FONT COLOR="#707070"><h1><big>Chapter 1</big></h1><h2><i>Your House</i></h2><FONT COLOR="DarkGrey"><p>You awake. Definitely day light outside... But did you wake up late or early?</p><p>Your alarm clock is flashing 12:00. stuck at that time until you change it. Had the power gone out?<p><p>Thank goodness school is out, your mother not here to bug you out of bed.<p><hr /><FORM METHOD="LINK" ACTION="page1.htm"><INPUT TYPE="submit" VALUE="Sleep more"></FORM><FORM METHOD="LINK" ACTION="page2.htm"><INPUT TYPE="submit" VALUE="Get up"></FORM></body></html>

Edited by Goweigus
Link to comment
Share on other sites

Oh boy that's going to take a lot of pages. 1. That's a strange way of using forms. Why not just use normal links - or, if you must have buttons, something like:<input type="button" value="sleep more" onclick="window.location='whatever.html'" />2. A much better (easier) way of doing this is probably to have have a databse store the different branches of the story. That way, when someone chooses a route, all that happens is the same page is reloaded with a new parameter. The page uses the parameter to find the right bit of the story. Say every time you come to a fork in the story, you call the first fork left and the second one right, and number the junctions. That might look like:<input type="button" value="sleep more" onclick="window.location='story.php?fork=1&option=left'" /><input type="button" value="get up" onclick="window.location='story.php?fork=1&option=right'" />You will need to learn PHP and basic MySQL for this, but it really will be the simplest way. Then, to fetch the data, you would have a page something like this (demo purposes only, may not function right!):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /><title>My Story</title></head><body><?php$mysqli = ("hostname","username","password","database");$fetch_story_sql = "SELECT content, left, right FROM story WHERE fork='$_GET["fork"]' AND option='$_GET["option"]'";$fetch_story_res = mysqli_query($mysqli, $fetch_story_sql) or die(mysqli_error($mysqli));$info = mysqli_fetch_array($fetch_story_res);$content = $info["content"];$left = $info["left"];$right = $info["right"];echo '<p>'.$content.'</p><input type="button" value="$left" onclick="window.location='story.php?fork=($_GET["fork"]+1)&option=left'" /><input type="button" value="$right" onclick="window.location='story.php?fork=($_GET["fork"]+1)&option=right'" />'?></body></html>

This would run off a database with fields for the fork number (section number),option (whether this is the left or right option from the precedng section), content, and left and right, which each contain the option text you want to display. You only need one page and it will automate everything. Again, this is a demonstration - further thought may need to go into it, but that's the idea and power of databse driven PHP.

Edited by chibineku
Link to comment
Share on other sites

Haha sounds like a really helpful suggestion, unfortunately I feel incapable of learning more than what I can do through copy/paste and changing values and adding text. I went with the separate file for every page because I don't feel I have the attention span (maybe some adhd type stuff haha) or capability to learn anything much more complicated. It certainly would be cool not to have to make tons of files the way I am doing it, but unless someone is willing to take the time to show me how to do it some other way, I am out of luck lolWhat you suggest seems to make sense to me, but theres no way I will be able to learn enough to do something like that :) Oddly enough I have the patience to do it this way, but I need a little help to add some random replay values I am also doing basically the same thing in powerpoint because I can't seem to learn FLASHPS: haha I have the patience to do it the slow way, but not the patience/attention to learn the faster way :) I am html/java disabled! 95% of the work I am doing is copy paste! (thats why i won't even chance the format/colors between slides!)

Edited by Goweigus
Link to comment
Share on other sites

Fair enough, but that script, despite my caveats, is pretty much good to go...all you need is to enter data into a database table. I guarantee it'd take less time to learn that that it will to make all the relevant HTML pages. As for your initial question about random chance:If you want something to have a 25% chance of happening, that's 1 in four, so use the math.random function to generate a number between 1 and 4 and if the number is 1 (it could be any of them), then you redirect to the burning alive page, otherwise to the success page. Like this:<input type="button" value="go into the burning house" onclick="chance('25','burn.html','live.html')" />chance() would look something like this:function chance(rate,fail,succeed) {var goto; // this will hold the value of the page to go torate = 100/rate; //turns % into a real numberoutcome = Math.floor(Math.random()*1+rate); //gives us a random number between 1 and 4outcome == rate?(goto=fail):(goto=succeed);window.location = goto;}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...