Jump to content
MakeWebGames

Lucifer.iix

Members
  • Posts

    46
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by Lucifer.iix

  1. Do you also have a good reason ? Like: Objects make you smile a lot.
  2. @Bineye: Why do you want to do this ? Let the DB deside this: if Query: INSERT ..... INTO TICKETS gives a key error saying the key already exists. Than you know. Also you can just say: "Insert this if not exists, but UPDATE if doesn exists"   Now your doing a SELECT statement that will echo some text, and does nothing... Just make code that does SOMETHING (hopefully logical) and if that doesn't work for some reason like: "Ticket already exists". Throw a exception, like Throw New TicketProblem(SQL_UPDATE, "Ticket already Exists")   Happy Hacking: Roger
  3. What is the problem of being logged on twice ? It's the same user, so it would not make a difference. And if it does than your code has side effects. It's better to remove the bad code with side effects, than to try to cover up your mistakes after it. My users can logon as mutch they like, there loged-on or loged-off. They don't get extra point for loging on twice. Happy Hacking: Roger
  4. You can also make a procedure or a SQL script that uses transactions. So people can't give point, if they are very fast to two people. After you updated the DB there is always a little bit of time before you update `$my['points']`. And there for give more point than they own. The db value of point will go negative for that user.   Create Procedure `swapPoints` (in fromPK int, in toPK int, in amount int) -- First check the toPK user exists.... But please don't do this here, but inside the CALLING code, like your test framework or production code. Start Transaction; SET @amountAvailable:=0; -- Create's a LOCK, so `THIS` script will wait until, no-one is writing and than locks the record. SELECT `amount` INTO @amountAvailable FROM `users` FOR UPDATE -- We don't want to mutch or negative points. Transfered = [0 -> amountAvailable] SET @amountTransfered:=Greatest(0,Least(amount, @amountAvailable)); UPDATE `users` SET `points` = `points` - @amountTransfered WHERE `id` = fromPK; UPDATE `users` SET `points` = `points` + @amountTransfered WHERE `id` = toPK; Commit Transaction; -- Last thing to do is commit the change...   If you want to make it really secure, for cheating....   Happy Hacking: Roger
  5.   Good catch.... Let's fill in the friends like this: - Check if both users are not the same user. - Than Insert: 1st is the person with the lowest primary key and the other has a bigger primary key. Alter your DB so the User1 + User2 are a UNIQUE index. So you can only insert every friend-relation once.   If you make it like this, If A know B then B is also friend of A. And you only can be friend once with every person. Function isFriend($Username, $FriendName, $DBLink) { ..... return True/False; } Usage: if(isFriend("Me", "He", $DB)==true) { startChattingWith("He"); } else { throw new chatNotPosssibleException("Your not a friend of user `he`."); }   Happy Hacking: Roger And let me know how it's going... and if it's working for you...
  6. Lucifer.iix

    Question

    Looks like spagetti code to me.... Function Login() { <- I don't need a THING... echo $Name; <- Almost nothing..... echo $SomethingElse; <- Oeps, forgot about that one... }   If your login function needs a `username` and `password`, why not give it to him ? Like: Function Login($INeedAName, $INeedAPassword, mysqli $INeedADB, $MoreStuffINeed, .....) { return true/false; } Than you can for example test your code: Like: Assert.IsFalse(Login("I Don't Exist","1,2,3,4,5", $Link, ....)) Also: Why does LOGIN mean PRINT a string to the USER ? Isn't that something else.... Isn't it just better to just check the username and password and give back a boolean or throw exception. Than in production you always can make: Login(mysql_real_escape_string($_POST['username']), mysql_real_escape_string($_POST['password'])) So login doesn't care about $_POST array and the page that does the login. Doesn't care about FIELD names in a database some where.   Maybe a good read: http://en.wikipedia.org/wiki/Design_Patterns Rule number 1#: "Program to an 'interface', not an 'implementation'." (Gang of Four 1995:18) Your login function is a implementation of almost everything, and your interface Login(....) is empty ! So you API says: Login() <- Nothing needed, just pray it works correct.   Happy Hacking: Roger. Ps: Don't be mad in 10 years you will thank me for this. (When you work in a professional software company where they re-use there code and write tests.)
  7. Notice: Undefined index: id in C:\wamp\www\GameWork\send_points.php on line 10   It means your INDEX in your ARRAY doesn't exists. So for: MyArray = array('Index1' => 1, 'Index2' => 2); The index 'IdontExisttInThisArray' isn't in your array and there for is complaining. That is the translation of your ERROR (It's NOT a warning!). So, that said: If you don't want to show a form when you don't have a id then try branching. like: If(isset($SomeArray[$SomeIndex])) { echo '<form.....'; } else { throw new HustonWeHaveAProblem("Ohhhh, no !"); }
  8. Running a script every 6 seconds to increment a counter in a table is maybe a little bit to mutch. Maybe you can calculate the period until now. Let's say person starts at time=0:00 and has 10 logs. After 62 seconds, he will have (Now-StartTime) = (62 seconds div 6) = 10x a FULL period's. So that will make 10+10 = 20 logs. You don't need to update a table for this every period of time. If you store the `formula` you only have to update the table when the formula changes and not the end result. So amount of logs of a user = Amount in DB + Amount in Running Scripts.   Ps: If you want to update the web page (GUI on the client) then you can use AJAX if people already said. But that's just something totally different. That's about updating a small piece of your webside with HTML or parse HTML from XML into your webpage.   Happy Hacking: Roger Keulen.   Ps: Let me know if it works for you. Or need some extra help.
  9. I like this page: http://zurb.com/ looks also great on a device. For bandwith and performance you have to split the HTML in segments. How more the thing changes the smaller the segment can be. And than parse it on the client with a simple java script and XML. But you have to make shure your caching is working correct, so images only being send once. If not cached public some where downstream. So if you know for shure it doesn't change untill then inforce caching (not ask, if-changed-after) otherwise use the ETAG header . function fetchData(url, onStatusOk) { console.log('fetchData: ' + url); var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { if(xmlhttp.status==200) { onStatusOk(xmlhttp); } else { console.log('fetchData: ' + xmlhttp.status + ' Error'); } } } xmlhttp.open("GET", url, true); xmlhttp.send(); } You need some plumming to parse it like:   function getPageId(elementID, url) { console.log('getPageID: ' + elementID); fetchData(url, function(xmlhttp) { sniplet=document.getElementById(elementID); sniplet.innerHTML=xmlhttp.responseText; runAllScripts(sniplet); }); } function runAllScripts(sniplet) { scripts = sniplet.getElementsByTagName('script'); if(scripts) { for (var i=0, max=scripts.length; i < max; i++) { script = scripts.innerHTML; delay = scripts.getAttribute('data-delay'); if(delay) { setTimeout(function() { console.log('Script delayed run: '+script); eval(script) }, delay*1000); } else { console.log('Script run: '+script); eval(script); } interval = scripts.getAttribute('data-interval'); if(interval) { console.log('Script interval run: '+script); setInterval(function() { console.log('Script interval run'); eval(script) }, interval*1000); } } } } It's beta code, but it works great. But you also can use JQuery for it. http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first is a great start. This is only a simple parse by `id` sample, but you will get the point. You can do this also with xml and dom parsing, so you going to parse innertext of the whole page. (Navigation, titles, etc...) So your <div class="nav_main"> get's it's <ul><li>.... parsed from xml, but using DATA inside makes it smaller. So HTML inside the XML as data elements. HTTP and XML headers/elementsize can make a lot of extra overhead for simple data. So you have to make some dicisions. But "IF" you click on main-menu item 1 and you ALWAYS go to main-menu->Sub item 1. Then only in that xml file has the MAIN nav and SUB nav have to be updated. in the other XML there arn't main-menu element's so your menu stay's in place. (Also with page titles, etc.) And if that file doesn't change mutch because of the static scripts inside it that load dynamic data. These long xml files get's cached. You want the smaller once dynamic, but stack them full with dynamic data that makes the overhead low. (thus not to small) With simpe changes in navigation or other tricks you can try to play with this. And for the webpage: taste, age and do you support `other` devices. If you make it for all people, make shure color blind people see some contrast. And don't create stroboscobe effects. That's all. :cool: Happy Hacking: Roger
  10. I can clearly see, these two PHP strings are not equal. PHP is really horrible with types, just like Java. It's really embarising bad. Clueless about why these awfull languages get's mainstream. Maybe `quick and dirty` has something to do with it. :D Happy Hacking.
  11.   Maybe just try to tell what you want to do. Do you want to store data in a database for searching/selecting ? like: CURRENT_TIMESTAMP() + ..... Are you writing PHP code for the war and are all people inside your WAR online at the time and doing HTTP request ? like: if(Time->Now() =< War->EndTime()) { ....   Maybe explain more. Happy Hacking: Roger.
  12. Sorry to say: How can i test this ? Wait until the correct date ? :cool: $Context->DateTime()(); <- This is the time, and i'm clueless about the implementation. So: $Context->DateTime() can return a test datetime function or a production datetime function like: time(). So, if your implementation is dependend on time, then you have to inject your dependencie. That way, your API isn't lying at you. Look: "i'm dependend on nothing and only my friend knows to use me." :o Ps: I use my (small!) context as `global space` and carry it around. :( There only leaf objects (tree object graph) in it or simple functions like: time. Happy Hacking (and testing) : Roger
  13. Do you mean PHP code that fires a mysql execute function with a insert statement into a table ? Or a stored procedure that has params that will be inserted ? Please give more information: - What do you try to do. (Like: Take input from GUI, check constains, insert in table...... jada, jada, jada....) - What is your (best) motivation to do it. (Like: performance, clean coding, patterns, testing...) Thanx. Happy Hacking: Roger
  14. If these prepared statements are getting stored on the serverside so they can be shared, that would make a difference of course. Because than you would have better, re-usable and stable SQL code with a little bit of overhead. But i just `generate` my php/sql code from the database. So i know all the names, types, relations, constains, so i can use set theory and monads to do this stuff. Persons::Insert(...,...,...)(); '()' <- Invoking the magic monad, that creates the whole thing. so i can pass it around leazy, and invoke it on a `foreach` itterator. Like: foreach(Model::Persons->Top(5000)->Page(2, 50)->OrderBy(Model::Person::FirstName, Model::Person::LastName)->Join(Model::Account)->Where(Model::Person->FirstName->Like("A*")) as $Person) { [here the magic happens..] => object: Linq2PHPEntities->Invoke() = Record Itterator ! }   It's called 'Monads': http://en.wikipedia.org/wiki/Monad_(functional_programming) So: File("longfile.txt")->Columns(";")->Column(2)->Average() => Not a result, it's a function chain that when invoked will result in a itterator with a list. The whole things is a expression tree from a chain of functions. The only thing i need objects for is to tell the stupid php language what type, what it is. So Max(Array(array(1,2,3,4), array(3,4,5,6))) => Array(4,6) so i can bind: WithResult->Column(2) => array(6) or with WithResult->Max() = 6. That means: Yes, Model::Person->TelephoneNumber->Like("A*") wil make ZEND studio know this is wrong before even TRY to run a test on this. Because it's not in my numbermonad, so even intelliscence when writing code know's it's a number and not text. So it's totally type safe and i don't use STRINGS in my expression tree to build SQL. That means: "Find Reference" gives me ALL the references of a object. He never can find them inside a SQL string. So you don't know where "firstname,...... from persons....." is used, and your programming enviorment doesn't know. When using types, you can ofcourse.   Happy Hacking: Roger.   Ps: Good video and extreemly hot babe: Or a dull old man from Microsoft Research: (The genius: Brian Backman)
  15. As long computers are calculators, i would go for math. Like: http://en.wikipedia.org/wiki/Combinatory_logic http://en.wikipedia.org/wiki/Lambda_calculus   Example: database table JOIN ??? ohhh, you mean the: http://en.wikipedia.org/wiki/Cartesian_product   Happy hacking ! Ps: If you don't understand math, 99.5% chance your building object graphs with a OOP Language. ;)
  16. Btw: Maybe a idea. I'm going to make a financial game so maybe it doesn't work for you. Some one who is `fresh` starting the game is, `level` => 0 (Normal situation) The maximum level you can get is the limit to 1. The worst level you can get is the limit to -1. So i have a `normal` middle and two bounderies that are limit's that can not be reached. (in normal situations and 64 bit floats) But because all my params have the same scale [0->1, 0->-1], i can multiply and devide them without side effects. Thus my result is also in that range. And on the end i'm going to use a *amplitude and +offset, to create the number to be used.   Happy Hacking and good luck with the game: Roger.
  17. Ok, got it, i think..... ((WILL*n)/5)+(LEVEL/5) -> n is difficulty from 1 -> 0 than: n^1.2 will make it more harder for 0.1 -> 0.1^1.2 = 0,063 -> 37% less than normal So scale it with a number above 1. Maybe like: N = (n^1.5) - - - Updated - - - Yeah, sorry. Didn't understand the labels so i just guesst it. I think just changing the n^1 to: n^1.5 or so would do the trick.
  18. Btw: ((WILL*n)/5)+(LEVEL/5) Found a `bug`.. WILL = 0 can give a result... Like: "My will to do this is 0, but +LEVEL make me want to do it ?"   Here are some wiki's about a good math function and distibution to use: http://en.wikipedia.org/wiki/Sigmoid_function http://en.wikipedia.org/wiki/Normal_distribution   Happy Hacking
  19. Sorry, but i'm a New Bee, and i am clueless about mccode. What's `will`: Integer, real ? Level looks like a integer i think. So level = 0 , success = 0% ? And `n`, number of attempts ? Please give more info if you want to have a formula designed. Btw: This one is always liniar. And you also can devide the endresult by 5. Example non liniar: Level = [0 -> 1] (Next level is for example = +10%, so: .1 + (10% of .9) = 0.19 and not 0.2) And 1 is NOT included. You can get some infinite, and 0 is difficult, so 0.00001 also does the trick. Otherwise you have to check for 'divide by zero' the whole time. Extreme small value is mutch code friendly. Then you can give it some scale: ScaledLevel = Level ^ Scale Example: Expert user that has a level of: 0.75 ScaledLevel = [Level = 75%, Scale = 1.0] = 75.0% <- Liniar ScaledLevel = [Level = 75%, Scale = 1.5] = 64.9% ScaledLevel = [Level = 75%, Scale = 0.5] = 86.6% Beginner user that has a level of: 0.25 ScaledLevel = [Level = 25%, Scale = 1.0] = 0.25% <- Liniar ScaledLevel = [Level = 25%, Scale = 1.5] = 12.5% ScaledLevel = [Level = 25%, Scale = 0.5] = 50% So: Scale = 0 > Beginner > 1 > Expert > 2. Thus: if it doesn't matter, if your a beginner or a expert, Scale = 0.00001 would do fine. 1% ^ 0.00001 = 0.999953... And otherway around also works: 99.9% ^2 = 99.8% and 11.1% ^2 = 1.23%   Happy Hacking.. Ps: please post what all the parameters are and what range or set there in.
×
×
  • Create New...