Forum Moderators: open
What I'm trying to do is figure out how to make a button/link to produce random results within a certain set values. For example, if you go to attack someone in the RPG, you are a level 10 and the guy you're attacking is a level 9, so you have x number of things that can happen and it will randomly choose the results based on the information from the database, and the higher up you get the better the results. Do you follow what I'm trying to accomplish? I don't even know what that type of code is called. I'm hoping you guys can help me out on this. If you could, I'd really appreciate it. Thanks for your help and time in advance.
Edit: I forgot to mention, I was told by a friend that this is a Java script, that's why it's in here, if it's not, I'm sorry for posting it here.
[edited by: Leveecius at 3:33 am (utc) on Nov. 3, 2007]
Now as for the non-Java applet script written there, that seems like it would work, I will try it a little later today. Only problem I forsee with it is I don't see how that would tie itself into information with my mysql database. But I appreciate the scripting, at least it gives me a place to start. Thanks for the help again guys, I really appreciate it. If it is a Java Applet, would anyone be able to expound on that a little?
You have 2 options:
1 User presses "Attack", page refreshes with results page. This would post the data to a server side script which would produce the result.
2 User presses "Attack", JavaScript uses AJAX to call aforementioned server side script.
3 User presses "Attack". JavaScript calculates result, sends result to server side script via AJAX.
4 User presses "Attack". JavaScript calculates result, and uses DOM to change page on the fly.
Sorry, got carried away.
1 is most browser-compatible.
2 is probably better for modern browsers and presentation.
3 kinda defeats the object calculating it on the front end and then having a back end anyway.
4 difficult to code, and probably quite slow.
I guess you have a back-end anyway for your SQL?
My code above was ment to tie in with the rest of the script if it was writen as JavaScript if not it wont work unless you re-think your design or want to open the doors to cheaters.
ps Dabrowski surely 4 would be the fastest as it dosn't have the overheads of waiting for the server to respond.
5 has this speed as well as backing up all info
Dabrowski surely 4 would be the fastest
It really depends on how much processing the JS is doing. Making major calculations (such as calculating a simple AI) and modifying the DOM takes a lot of CPU time in JS. Compared to a decent server, maybe 2 secs for an AJAX refresh would seem preferable.
Both would work, that's just my oppinion, if I was doing it I'd do it that way.
And also as you pointed out, if you run the game in JS people could cheat, keeping everything on the back end mean they have to play by the rules!