Current location: Hot Scripts Forums » General Web Coding » JavaScript » Creating a browser RPG in javascript


Creating a browser RPG in javascript

Reply
  #1 (permalink)  
Old 09-27-08, 05:49 AM
SolidSamurai SolidSamurai is offline
Newbie Coder
 
Join Date: Apr 2008
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Creating a browser RPG in javascript

IMHO, this is the next step for me.

How would I go about doing this?

Would you start with button(value = "click" onclick(document.write("text")));, ie.?

I'll learn throughout the thread here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-27-08, 08:53 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by SolidSamurai View Post
IMHO, this is the next step for me.

How would I go about doing this?

Would you start with button(value = "click" onclick(document.write("text")));, ie.?
This question is so general, it's difficult to give you a meaningful answer. It's sort of like asking "if you're going to do a heart transplant, should you start with a #10 scalpel?"

The answer is, "It depends."

If you want to create a browser-based RPG, draw up a list of the game specs, play modes, and functions. It'll be a large list even if it's a simple game. Then start building the pieces, graphics, underlying code, etc.

A browser-based RPG is a pretty complex application; if you're new to Javascript and/or PHP you might consider starting with something a little less ambitious.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]

Last edited by End User; 09-27-08 at 08:56 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-27-08, 11:43 AM
Sdry Sdry is offline
Newbie Coder
 
Join Date: Sep 2008
Location: Belgium
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
You are aware client side scripts aren't exactely safe for your game ? depends what you are gonna use them for, but you should base on a server side language if the game is ment to be played clean , though if it's only a personal test, its doable.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-27-08, 09:38 PM
SolidSamurai SolidSamurai is offline
Newbie Coder
 
Join Date: Apr 2008
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
It wouldn't be client side. It's just point and click. Very simple stuff with mathematical functions incorporated (click a button to fight the monster and then click the button with attack value to attack the monster). No graphics (except for a few jpgs maybe), nothing of that sort.

It's practice for learning how to incorporate math functions in proper order (ie. a way of randomizing chance to hit enemy with weapon and then a damage ratio for weapon/player per current level). Something that I'd build upon.

Last edited by SolidSamurai; 09-27-08 at 09:40 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-29-08, 02:47 AM
SolidSamurai SolidSamurai is offline
Newbie Coder
 
Join Date: Apr 2008
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Okay...

Code:
<html>
<head>
<script language="javascript">


combatplayerattack=new Array();
combatplayerattack[0]="You barely catch ' + monster + ' with your ' + playerweapon + '";
combatplayerattack[1]="You ' + playerweapon + ' plunges deep into ' + monster + '!  Critical Hit! ";
combatplayerattack[2]="You swing your ' + playerweapon + ', but ' + monster + ' skimly avoids!";
combatplayerattack[3]="Your weapon is deflected!";
combatplayerattack[4]="Your attack misses completely!";
combatplayerattack[5]="From the reaction of ' + monster + ', it's clear that your ' + playerweapon + ' hurt it somewhat!";

var randomplayerattack = combatplayerattack[Math.floor(Math.random() * combatplayerattack.length)]

</script>
<button onclick="document.write(' + randomplayerattack + ')">Attack</button>
</head>
<body>
</body>
What's wrong with the script here? Other then the fact that I forgot to include values for playerweapon and monster.'

Also, I might be going too deep with this question but how do I include multiple values for different items, such as for a certain monster: I might include AC, to hit, and damage as well as the fact that they are holding a weapon, wearing armor, or even core stats (STR, DEX, WIS, etc.) that correspond with every npc/pc in the game? Would the monster itself be a function? Would the 'player' be a var of its own (in the code of the world itself rather then calling accounts from a database to define the 'player')?

Last edited by SolidSamurai; 09-29-08 at 02:53 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 10-03-08, 04:55 AM
SolidSamurai SolidSamurai is offline
Newbie Coder
 
Join Date: Apr 2008
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Nobody else interested in helping out?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 10-03-08, 12:11 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by SolidSamurai View Post
Nobody else interested in helping out?
The fact is that most of us have jobs, lives, wives, children, and other real-world obligations that prevent us from taking the time to code your stuff for you.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 10-03-08, 02:10 PM
SolidSamurai SolidSamurai is offline
Newbie Coder
 
Join Date: Apr 2008
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Dude, it's questions. Just answer my questions, no need for a hissy fit.

This also doesn't indicate that I want you to do it for me. I'm still trying to learn myself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 10-04-08, 06:42 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by SolidSamurai View Post
It wouldn't be client side.
If it's JavaScript, it's clientside. Simply because JavaScript runs on the client/browser.
JavaScript Code:
  1. <html>
  2. <head>
  3. <script language="javascript">
  4.  
  5.  
  6. combatplayerattack=new Array();
  7. combatplayerattack[0]="You barely catch ' + monster + ' with your ' + playerweapon + '";
  8. combatplayerattack[1]="You ' + playerweapon + ' plunges deep into ' + monster + '!  Critical Hit! ";
  9. combatplayerattack[2]="You swing your ' + playerweapon + ', but ' + monster + ' skimly avoids!";
  10. combatplayerattack[3]="Your weapon is deflected!";
  11. combatplayerattack[4]="Your attack misses completely!";
  12. combatplayerattack[5]="From the reaction of ' + monster + ', it's clear that your ' + playerweapon + ' hurt it somewhat!";
  13.  
  14. var randomplayerattack = combatplayerattack[Math.floor(Math.random() * combatplayerattack.length)]
  15.  
  16. </script>
  17. <button onclick="document.write(' + randomplayerattack + ')">Attack</button>
  18. </head>
  19. <body>
  20. </body>
Other than the obvious missing variable declarations you mentioned, you have the quotes wrong almost everywhere.

To insert the value of a variable in a string, you must split it to two strings:
JavaScript Code:
  1. myVar = "string one, " + myOtherVar + ", string two";

Add two doublequotes here as well:
HTML Code:
<button onclick="document.write('" + randomplayerattack + "')">Attack</button>
Using document write there isn't much point as you can only do it while the page loads, but I'm assuming you already knew that and used this as a testcase.
Edit: I just noticed the <button> tag was in the <head> tag too, where it won't be rendered as only stuff in <body> normally is.

End User has a point, tho be it a bit hidden. Always check the syntax, preferably after each new line. The problems you had here are easy to spot with a highlighting editor like say tsWebEditor or UltraEdit, or even the default text editor gEdit in Linux distributuions using GNOME.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.

Last edited by TwoD; 10-04-08 at 01:52 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 10-06-08, 01:12 AM
SolidSamurai SolidSamurai is offline
Newbie Coder
 
Join Date: Apr 2008
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
End User has no point. Hiding your point is useless.

He's useless. Just felt I had to say that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting browser to resize and remove tools, scrolling etc. Tonio9 JavaScript 3 05-02-07 04:42 PM
javascript and browser setting sharad JavaScript 2 09-14-06 10:55 AM
Creating Browser Extension Barnz1986 Windows .NET Programming 2 08-28-06 06:07 PM
detect user browser on JavaScript support? torwill JavaScript 3 06-18-05 05:40 AM


All times are GMT -5. The time now is 08:12 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.