ID:152976
![]() May 7 2005, 2:03 pm
|
|
I was reading chapter 10 in the dm guide,I found lists very hard and when wizkidd coded the curse seal and I tried to study it I still did not get it.I was wondering if somone was to explain this to me step by step.
|
Broly103 wrote:
Hey whats does this ! do, I get confused everytime I see it. I recommend reading the section that I've written about the ! operator in my Hello Operator BYONDscape article. It should clear things up for you! I would actually recommend reading the entire article. =) |
Also, you can sort of index lists ( The posted code doesn't really show indexing ):
Ex. mob Feel free to correct me if I made a mistake, or add something as you see fit. |
Audeuro wrote:
Also, you can sort of index lists ( The posted code doesn't really show indexing ): DeathAwaitsU wrote: Now then, lets add everything we bought into our shopping trolley: var/list/shopping = list("apples","oranges","bananas") Notice the indexing at the third last and penultimate line. But yeah yours was probably a better example. Perhaps not the most practical though. |
DeathAwaitsU wrote:
Audeuro wrote: > var/list/shopping = list("apples","oranges","bananas") Notice the indexing at the third last and penultimate line. Ahh, didn't read your thoroughly, sorry. ( On an unrelated note, associative lists don't seem as useful in DM as they are in C++ to me ) |
Broly103 wrote:
I was reading chapter 10 in the dm guide,I found lists very hard and when wizkidd coded the curse seal and I tried to study it I still did not get it.I was wondering if somone was to explain this to me step by step. Let's say we have a shopkeeper in our game: mob/npc/shopkeeper Our shopkeeper has items that he holds in his for_sale list: Now, before continuing, let me explain something about lists. When you define any variable, that variable is automatically initialized to null unless the programmer chooses to initialize it to something else: //my_var starts out equal to null One basic way of initializing a list is to use the list() proc. While defining a list is equivalent to telling the program what the list is, initializing a list is equivalent to actually creating the list. Therefore, if lists were grocery bags: //The knowledge of a specific grocery bag. One good rule to remember in DM is that lists should only be initialized at the point when they're needed. Following that rule is a good way to save precious system resources. Now, getting back to our shopkeeper: mob/npc/shopkeeper We run into problems here. When the player trys to buy an item, he'll need to know its price, right? In our current system, there's no really efficient way of doing that. Therefore, we'll decide to make for_sale an associative list in the format, item == price: mob/npc/shopkeeper Now, if we want to access the prices, we can do this: mob/npc/shopkeeper You see, to access the value of an element in an associated list, you use the format, associated_list["element"]. Therefore, in our for_sale list, for_sale["Sword"] is equal to 10, and for_sale["Shield"] is equal to 15. In atom.vars, the pre-defined associated list which I used in the other thread, the format is var = var_value. Try out the following example: mob/verb/See_Vars() |
Audeuro wrote:
( On an unrelated note, associative lists don't seem as useful in DM as they are in C++ to me ) You must not be making full use of them then: Associative lists are one of the biggest time and resource-savers in DM. Very, very useful. I recommend reading Lummox's article on the subject. |
Wizkidd0123 wrote:
Broly103 wrote: mob/npc/shopkeeper Our shopkeeper has items that he holds in his for_sale list: > //my_var starts out equal to null One basic way of initializing a list is to use the list() proc. While defining a list is equivalent to telling the program what the list is, initializing a list is equivalent to actually creating the list. Therefore, if lists were grocery bags: > //The knowledge of a specific grocery bag. One good rule to remember in DM is that lists should only be initialized at the point when they're needed. Following that rule is a good way to save precious system resources. > mob/npc/shopkeeper We run into problems here. When the player trys to buy an item, he'll need to know its price, right? In our current system, there's no really efficient way of doing that. Therefore, we'll decide to make for_sale an associative list in the format, item == price: > mob/npc/shopkeeper Now, if we want to access the prices, we can do this: > mob/npc/shopkeeper You see, to access the value of an element in an associated list, you use the format, associated_list["element"]. Therefore, in our for_sale list, for_sale["Sword"] is equal to 10, and for_sale["Shield"] is equal to 15. > mob/verb/See_Vars() Its still a blur in my head. |
They are actually quite useful, I've seen more reason to use them in DM(game design, anyhow) than to use them in C++. Administration, shopping, banking, and grouping alike variables are just the tip of the iceburg on some of the reasons I've used them.
P.S. Keep in mind, I've only just learned C++ and haven't any hands-on experience of writing programs of my own in it. |
I was wondering if you would use them for learining new attacks and how do I do that,please an example not the full code so I can learn to do it myself for once :P.
|
How about no code at all? Pseudocode is a term that, if you havn't taken any formal education in computer programming, you may never have heard. The word-root "pseudo", in case you don't know, generally means "not quite". Pseudocode is like code, but lacks the specific nature of code that is actually compiled and run.
Pseudocode is often used by programmers who want to communicate ideas with other programmers who do not write using the same language. It is also used by programmers who want to document the flow of a program before they actually write the real code out. Here is some pseudocode that might help you allow learning of new attacks using lists. players have: "attacks", a list each element "attackname" has a value of attackdamage (a number) on creation of a new player: learn ("karate chop", 1) procedure "learn" ("name",damage) add "name" to list "attacks" set list element "name" equal to damage procedure "attack" ask player "which attack do you use?" player picks attack from list "attacks" player's choice saved in variable "attack" ask player "which target do you choose?" player picks target from opponents in range player's choice saved in variable "target" reduce "target"'s health by "attack"'s value in list "attacks" display to everyone, "target" is attacked! The purpose of this code is to outline a general structure for code without going into the code's specifics. I hope that my pseudocode is understandable enough that you can visualize a system where players can learn new attacks. In your game you wouldn't want players to be able to type "learn SUPERCHOP 5000" and get an unrealistically good attack. However, for demonstration purposes, I think you can understand. I challenge you to write BYOND code using the pseudocode I wrote above. If you need help with specific things, post your questions along the way. The application of lists is simple here, but simple applications will surely lead to better ones. |
Well, it might be pretty confusing until you understand basic lists, but once you do, read over that post again!
For future reference, Broly, please don't use the "Reply with Quote" button unless you're uing it for a reason, and even if you are, omit all of the quoted post with the exception of the relevant material. |
Rather than giving you a bunch of code, I'll just explain it.
Okay, here's the scoop on associative lists. An associative list is basically a big list of strings with a second tier of values tied to those strings. You know how you access indexes of a normal list, right? With the position of the value you want? Isn't it a bit tough to keep track of where an object is, rather than being able to name every single value? You can. A normal list would look like this: var/list/list = list("red","blue","green") An associative list looks like this: var/list/list = list("red"=rgb(255,0,0),"blue"=rgb(0,0,255),"green"=rgb(0,255,0)) How is this useful? It's useful in hundreds of ways! I can't touch upon hardly any of them! It's just useful for everything that you need precision and speed of access to. |
I'm just use to pressing the quote button XD.
EDIT:I'm going to pause my game for now,I'm going to study the dm guide till july and begin there.Its better then just asking how to do something,then in the end someone gives me the code and I learn nothing but just copy and paste the code -_-.When I need help in something in the dm Ill be sure to come to you guys for help :), tommrow the journey begins :P. |
Thats all you need to make a list.
Now lets say you remember something suddenly before going shopping, you'll have to add to the list:
So now lets say you're shopping and you look at your list and need to figure out how many things are in your list:
Now you must decide which item to buy first:
Ok so lets say you found it on the shelf:
Now you decide that you've run out of time and the only important things you need to get are located at the bottom and top of the list:
Now then, lets add everything we bought into our shopping trolley:
And now at checkout, the worker needs to empty the trolley:
Study all the different kind of things I've tried to show in one shopping adventure =P