Goose87 Posted March 31, 2008 Share Posted March 31, 2008 Hi guys, I have always had problems with arrays and I have always needed help with them. Mainly because I've never had much contact with them, but I feel this is a good time for me to use one, I just have no idea how to do them. I learn quickly, so I'm sure if someone just points me in the right direction I'll pick it up. The Problem: I have an online game, and I want to try a new method for the experience gained when a person does a certain skill at a certain level. At the moment if someone is level 8, and there is a skill at level 1, and at level 10, they gain the same exp if they do the level 1 skill, as a person who is level 1. I want them to gain the exp that they should gain at level 8 (which is slightly more). I'll give an example of what I want to achieve: Level 1: 10 exp Level 2: 20exp Level 3: 30exp Level 4: 40exp Level 5: 50exp ... Level 30: 300 exp. Ok, so lets assume the person gains 10 exp per level, but I want a limit on the amount of exp you can gain for the level 1 skill. So lets say you can have a skill at: Level 1 - Max exp 40 Level 5 - Max exp 90 Level 10 - Max exp 150 Level 20 - Max exp 200 Lets say someone who is level 30 (should gain 300 exp if they are doing a level 30 skill), does the level 1 skill. I dont want them to get above 40 exp for this, so I need to make sure thats limited. I think I have explained this to the best of my ability. If anyone has any questions, please let me know. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/ Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 Arrays are simple objects in php. An "Array" is literally an array of values/keys stored in a variable. eg, instead of doing this: $blue = "1"; $green = "2"; $red = "3"; ... i could do this: $colours = array("blue"=>"1","green"=>"2","red"=>"3"); or this: $colours = array("blue","green","red"); the difference in these two arrays is the first is setting a key=>value pair, the second is only setting values. so, to use the first array would be like: if($colours["blue"] == "1){ echo "True"; } to use the second: if($colours[0] == blue){ echo "True"; } When you only assign values the keys count from 0, so the first variable in the array would be keyed as 0. ------------ Ok so thats how to use and set basic arrays, im sure you can imagine the possiblities of arrays within arrays within arrays and practical uses. if you are still stuck on this idea, i think i would need to know how the user/players get experience? through kills/creatures? is there multiple ways to gain experience? hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/#findComment-505643 Share on other sites More sharing options...
Goose87 Posted March 31, 2008 Author Share Posted March 31, 2008 Ah ok, I managed to grasp the basic concept, but its when they do the whole... foreach($key => $array) blah blah i get very confused lol. Anyways, The player does a skill, on the page that im going to test this on to start with, the person chooses a skill from a drop-down menu, there is a level requirement for each one: 1, 5, 10, 20, 30, 40, 50 up to 100. There is going to be a maximum experience that you can gain associated with each one, so I'm assuming we need an array to store that. We also need an array to store the amount of exp you should gain at each level, i.e. level 1, 2, 3, 4, 5, 6, 7, 8, -> 100,. I suppose I then have to say, find the exp you should gain for your level ..... But im not sure how to do that.. Something like, hmm..I really dont know! If someone could help me out here i'd appreciate it. Then you compare the exp that you do gain with the max exp for that skill, and you'd do the same comparison with the skill onto the first array? Then you take the lowest value that there is? I.e. if they can gain 30 exp but the highest is 40, you get 30, if they could gain 100 but the max is 40, you take 40? If someone could convert this idea into code, I'd really appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/#findComment-505650 Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 Much easier if you use MySQL Database. It sounds like you need to revise your experience/skill structure. Most games use the character level, and enemy level to determine how much experience that characters gets for killing the creature, this means that when a character is a higher level they get less experience for killing lesser monsters. Each monster usually has a sort of "Base Experience", the initial amount of experience (usually the maximum) a character can gain from it, then they subtract the difference between the character' and enemy' level from the experience gained, thus enabling progressive gameplay . All the Skills a character should have is usually controlled by level (enable/disable) and by "Skill Points", eg you get a skill point every 5 levels etc, or can find them etc. Skill points would allow your players to choose a skill they want rather than a skill set by the game, this would allow for variations in game play and strategy. What you are trying to do is very complicated without some sort of database driven code, as in databases each "Array" can have as many values/keys etc as you like, eg muti-dimensional arrays, MySQL is also extremely simple to use, with phpmyadmin on the scene its a piece of cake to manage. I Strongly suggest you start using mysql as soon as you can, the SQL Syntax for the more complex databases can be quite mind-boggling at first, but once you have clear groundwork you can build you game a LOT easier. ------------------------ About your question though, what you are doing seems really complicated to me and i dont fully understand your concept, is there 1 skill per level? Is there a SET amount or a VARIABLE amount of experience gained per kill/event? Am i correct in assuming each skill can only have a maximum amount on experience? or does the maximum change each level? hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/#findComment-505677 Share on other sites More sharing options...
Goose87 Posted March 31, 2008 Author Share Posted March 31, 2008 I'll try and explain what I want again, I think there is a slight amount of confusion. The person is doing a skill, in this case, lets call it mining. They are mining ores from the ground, there arent any monsters in this case. They can mine a type of ore at level 1, 5, 10, 20 30, 40. The "mining level" of the person can be from 1->100. They can therefore mine the level 1 ore when they are level 50. What I want is two arrays, one for the amount of exp gained for their actual level, and one for the amount of exp you should gain from the skill. An example of whats wrong at the moment. You are level 1, to get to level 2 you need 100 exp, to get to level 3 you need 250 exp, level 4 is then 500. (These arent my figures though), the amount of exp that you need to gain goes up exponentially. If someone is level 9, they are gaining a set amount of exp PER click for the level 5 ore they are mining. The problem with this is that it takes too long to level up, because the amount of exp they need to get to level 10 from level 9 is double the exp from level 5 to level 6. What I want to achieve is when someone is level 9, they get MORE exp for mining the level 5 ore than someone who is level 5. I would also need a CAP though. So someone who is level 50 doesnt get MORE exp than someone who is level 9 mining the level 9 ore. This stops people mining the lower ores and gaining more exp than someone who is level 40 mining the harder ores I hope this explains it all a bit better. I'm sure I could just use 2 arrays here, and then compare the two values, but I may be wrong..? Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/#findComment-505685 Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 Ok i think i understand, could you not make the lower levels/skills less powerful, eg it takes more hits/clicks to mind 1 piece of experience. So the higher the level, the more that person can mine in one go? Rather than patching up an experience hole that could potentially be exploited . This way a Level 5 char mining a level 5 rock would mine Slower than a level 6 char mining a level 5 rock. ------- there would need to be balancing between speed and level but i believe this would be an easier/efficient solution hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/#findComment-505695 Share on other sites More sharing options...
Goose87 Posted March 31, 2008 Author Share Posted March 31, 2008 That feature could be added, but that wouldnt solve the problem I have at the moment. I would still get users sending me messages saying "With this experience it will take me 81*5 minutes to get the next level" and stuff like that. I need to somehow make an array. I will TRY my method, if you could explain to me how i query if a number is in an array? I am coding a different script at the moment and ill show you what i want to do: i want a multi-array thing, so it'll be: array($array1=array(1, 2, 3, 4, 5), $array2=array(6, 7, 8, 9, 10)) how do i check which array its in? Or if that coding is a pile of rubbish: how do you find out what the result is if you have: arrray(dog=>1, cat=>2, bird=>3)? If you have the value of 3, how do you find out what the word is? You put earlier: if($colours["blue"] == "1){ echo "True"; } but how do i query to find what the value is if I only have 1 of the things, i.e. I have the value of 1, or i have blue, how do i find the other one that corresponds with it? Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/#findComment-505715 Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 ok , some tips on using arrays for comparison and validation: this: array($array1=array(1, 2, 3, 4, 5), $array2=array(6, 7, 8, 9, 10)) should be: $array = array("array1" => array(1, 2, 3, 4, 5), "array2" => array(6, 7, 8, 9, 10)) To check which variable a specific number is in you could use: if(in_array($number,$array['array1'])){ $Current_Array = $array['array1']; } ---- To check wether a colour exists you could use if(isset($colours[$thecolour])){ echo($colours[$thecolour]); } to find a colour from the colour number you could do something like: $keys = array_keys($colours); foreach($keys as $key){ if($colours[$key] == $colour_number){ echo("Colour is $key"); } } hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/#findComment-505737 Share on other sites More sharing options...
uniflare Posted March 31, 2008 Share Posted March 31, 2008 See Also: http://www.php.net/manual/en/ref.array.php Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/#findComment-505740 Share on other sites More sharing options...
nadeemshafi9 Posted March 31, 2008 Share Posted March 31, 2008 this may be old php but i find it easy $an_array[1][name] = "d"; $an_array[1][colour] = "d"; $an_array[1][fav] = "d"; $an_array[2][name] = "d"; $an_array[2][colour] = "d"; $an_array[2][fav] = "d"; then $i=0; foreach($an_array as $ele){ echo ele[$i][name]; echo ele[$i][colour]; $i++; } or for($i=0;$i<count($an_array)){ echo an_array[$i][name]; echo an_array[$i][fave]; } NOTE i missed out '' and some $ to make it harder for u Quote Link to comment https://forums.phpfreaks.com/topic/98816-an-array-problem/#findComment-505750 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.