Jump to content

zerotolerance

Members
  • Posts

    15
  • Joined

  • Last visited

Everything posted by zerotolerance

  1. Thank you I just got it! That was so simple Just one more question: Since it's number of tiles -1, what would happen to the 20th tile? Since the first run would be with 19, then 18, etc.
  2. Hello I recently started learning Actionscript, and I am sort of stuck understanding the logic behind something, so if someone can please explain it to me clearly and dumb it down to a beginners logic, it'd be awesome. My code is simple. I am making a concentration game, and I used arrays to generate tiles (max 20 tiles, so two of each cards from 0-9): 00 11 22 33 44 etc... Anyways, like all games of concentration, you need to add randomness, so I I added a for-loop (btw, I'm following a tutorial, I didn't actually write this ), and it basically swaps the numbers around so you get different combinations everytime. This is the part that confuses me... package { // importing classes import flash.display.Sprite; // end of importing classes public class Main extends Sprite { public function Main() { // variables and constants /* Different types of constants - int represents an integer that can be negative or positive, called signed integer - uint represents an integer that represents ONLY positibe numbers, called unsigned integer - Number (uppercase "N") is used to represent whole and fractional numbers, regardless of their sign (i.e: positive or negative) ** Important: you can use Number to define constants if you are unsure of int/unit */ const NUMBER_OF_TILES:uint=20; var tiles:Array=new Array(); // end of variables and constants // tiles creation loop for (var i:uint=0; i<NUMBER_OF_TILES; i++) { // push() method adds an element to the end of the array // Math.floor() method returns the number that is less than or equal to the parameter inside (i.e. rounds down) tiles.push(Math.floor(i/2)); } trace("My tiles: " +tiles); // end of tiles // shuffling loop in order to create randomness (it's very easy to guess a game of concentration without it) var swap, tmp:uint; for (i=NUMBER_OF_TILES-1; i>0; i--) { swap=Math.floor(Math.random()*i); tmp=tiles[i]; tiles[i]=tiles[swap]; tiles[swap]=tmp; } trace("My new shuffled tiles: "+tiles); // end of shuffling loop } } } For the second for loop, the person is using the condition i = NUMBER_OF_TILES-1, so if we go with the defined variable above which is 20, 20-1 is 19. 19 is added into swap, so a number between 0 and 19 (19 not included), let's say for simplicity sake it's 4 (rounded down with Math.floor()). Can someone tell me what happens now? With the above code, i get the following results: However, if I remove the tiles[swap]=tmp;, the output is: Can someone tell me the significance of the tmp? And explain me how the swap is actually occurring, and the logic behind it. In my understanding, if swap generates 4, then it's tmp= tiles[19] tiles[19] = tiles[4] What does that mean exactly.. Thank you By the way, if it helps, the tutorial is using Fisher-Yates shuffle algorithm. Edit: ignore my little comments. They are just notes I made for myself.
  3. Hi guys, I'm trying something new so bear with me . I have a dropdown box <select id="option" name="number" onchange="changeTeam()"> <option value="0"></option> <option value="1">Team 1</option> <option value="2">Team 2</option> <option value="3">Team 3</option> <option value="4">Team 4</option> <option value="5">Team 5</option> </select> <td class="tb"> <label><img id="Starter1" src="images/Empty.gif" /><br /><input type="radio" id="Starter" name="Starter" value="1" checked="checked" /></label> </td> <td class="tb"> <label><img id="Starter2" src="images/Empty.gif" /><br /><input type="radio" id="Starter" name="Starter" value="2" /></label> </td> <td class="tb"> <label><img id="Starter3" src="images/Empty.gif" /><br /><input type="radio" id="Starter" name="Starter" value="3" /></label> </td> My javascript code is: var Options = Array(['Empty','Empty','Empty'], ['First','Second','Third'], ['Fourth','Fifth','Sixth'], ['Seventh','Eight','Ninth'], ['Tenth','Eleventh','Twelfth'], ['Thirteenth','Fourteenth','Fifteenth']); function changeTeam(){ // this is where I am stuck... } What I want to do is whenever the drop down changes, a value is picked and from that value, the corresponding array values are replaced. So If I was to pick Team 1, then Empty would be changed to First.gif, Second.gif, Third.gif... I'm not sure on how to do this.. I read somewhere it says using .attr and using .replace(/^(A-z, but I just don't know where to start. So If somoene can shed some light, would be great.
  4. Still trying, and confused :/.
  5. Just fixed the $starter problem, I put the error display thing but no errors are displaying. If I remove the trainer query, the pokemon query seems to work just fine.
  6. Yeah, I'm using PDO. Sorry about that... I found the error I'm guessing. $starter has no value, if I try to set it to other fields, I get the error Integrity constraint violation: 1048 It also says I'm using a field which cannot be null. Could this be why the query won't get added?
  7. Hi, So I have this piece of code: // getting the pokemon status $pokemonsql = $this->connection->query("SELECT * FROM ".TBL_POKEDEX." WHERE pokemon = '$starter'"); while($pokemonrow = $pokemonsql->fetch()) { $hp1 = ($pokemonrow["baseHP"]/10)/2; $hp2 = ROUND($hp1)*10; $attack1 = $pokemonrow["attack1"]; $attack2 = $pokemonrow["attack2"]; $attack3 = $pokemonrow["attack3"]; $attack4 = $pokemonrow["attack4"]; $gender_random = RAND(1,2); if($gender_random == "1") { $pokemon_gender = "Male"; } if($gender_random == "2") { $pokemon_gender = "Female"; } // everyone should have a chance of getting a shiny starter $shiny_random = RAND(1,40); if($shiny_random == "40" ) { $shiny = "Yes"; } else { $shiny = "No"; } } // trainer query $query = "INSERT INTO ".TBL_USERS." SET username = :username, password = :password, alliance = :alliance, avatar = :avatar, gender = :gender, usersalt = :usersalt, userid = 0, userlevel = $ulevel, email = :email, timestamp = $time, actkey = :token, ip = '$userip', regdate = $time"; $stmt = $this->connection->prepare($query); return $stmt->execute(array(':username' => $username, ':password' => $password, ':usersalt' => $usersalt, ':alliance' => $alliance, ':avatar' => $avatar, ':gender' => $gender, ':email' => $email, ':token' => $token)); // pokemon query $query = "INSERT INTO ".TBL_POKEMON." SET Trainer = :trainer, OTrainer = :otrainer, Pokemon = :pokemon, Shiny = $shiny, Level = 10, EXP = 1001, EXPN = 1331, HP = $hp2, MHP = $hp2, Gender = $pokemon_gender, Attack1 = $attack1, Attack2 = $attack2, Attack3 = $attack3, Attack4 = $attack4, Item = None"; $stmt = $this->connection->prepare($query); return $stmt->execute(array(':trainer' => $username, ':otrainer' => $username, ':pokemon' => $starter)); } The only problem I'm having is the information is being stored into TBL_USERS but nothing is happeningto TBL_POKEMON. Can anyone point me in the right direction? I've tried changing the stmt variables too, but nothing. The information just won't get inserted into tbl_pokemon.
  8. So how would I add it to query? Isn't it inside the query if there's a variable defenfing it inside the code?
  9. Sorry for double posting but I sorta do have it in 2 brackets, my null fields are in the second bracket.
  10. But how is it updating when I'm saying my query to "INSERT INTO ".TBL_USERS.""? o.o
  11. Hi guys, I have this code: $query = "INSERT INTO ".TBL_USERS." SET username = :username, password = :password, usersalt = :usersalt, userid = 0, userlevel = $ulevel, email = :email, timestamp = $time, actkey = :token, ip = '$userip', regdate = $time"; $stmt = $this->connection->prepare($query); return $stmt->execute(array(':username' => $username, ':password' => $password, ':usersalt' => $usersalt, ':alliance' => $alliance, ':email' => $email, ':token' => $token)); however, i added a new column called "alliance", which is null. However when I try to submit my data, this error pops up: If I remove the alliance, it seems to work just fine.. have I done something wrong? The error on the page seems to be showing the value of the alliance I orginally put in the registeration form, but it won't get recorded due to this error.
  12. Perfect Thank you so much but I'm still unsure of how I can write [m] if($suboption !== "option1" || $suboption !== "option2" || $suboption !== "option3" || $suboption !== "option4" || $suboption !== "option5" || $suboption !== "option6" || $suboption !== "option7"){ $form->setError($field, "* Unexpected error with option"); }[/m] An easier way
  13. Hi , I'm new on this forum so don't judge too hard.. But I have a few questions. I am recently new to PHP as this is my first computer language I've learnt besides HTML. My first question is, what's the difference between !== and !=, and is it more secure to use !== when comparing two fields such as passwords? I've different things and this has confused me.. And my second question is, I have this piece of code /* option error checking */ $field = "option"; // Use field name for option /* Check if the option picked is from the list of options to choose from*/ if($suboption !== "option1" || $suboption !== "option2" || $suboption !== "option3" || $suboption !== "option4" || $suboption !== "option5" || $suboption !== "option6" || $suboption !== "option7"){ $form->setError($field, "* Unexpected error with option"); } I'm guessing in the long run, this will slow down my script.. is there an easier way of checking without using || $suboption !== and is it okay if I've used !==? Like I said I'm new to this so please don't flame.. I've done some research but I can't seem to find some accurate answer. Thank you, ZT
×
×
  • 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.