ID:163324
 
give_cash(mob/M as mob in world)

How can I make it so the user of this verb will not be shown in the list?
You gotta do this manually.

give_cash()
var/list/L = list()
for(var/mob/M in world)
if(M.client&&M!=src)
L += M.name
L[M.name] = M
var/choice = input("Give cash","Give cash") as text|null in L
if(!choice||!L[choice])
return 0
var/mob/M = L[choice]
//add money to the selected player.
In response to Ter13
now my head is starting to hurt
In response to Hellonagol
        give_cash()
var/list/L = list()
for(var/mob/M in world)
if(M.client&&M!=src)
L += M.name
L[M.name] = M
var/choice = input("Give cash","Give cash") as text|null in L
if(!choice||!L[choice])
return 0
var/mob/M = L[choice]
if(usr.made==0)
usr << "<font color=green>Please make a character first.</font>"
else
if(M.key=="usr.key")
return
else
var/A = input("How much gold would u like to give this person?")as num
A = round(A)
if(A > usr.cash || isnull(A))
usr << "<font color=green>You dont have that much cash to give away!</font>"
else if(A <= 0)
usr << "<font color=green>You give away no cash!</font>"
return
else
M.cash += A
if(usr.team=="Good")
M << "<font color=blue>[usr]</font> has given you $[A]."
else
if(usr.team=="Bad")
M << "<font color=red>[usr]</font> has given you $[A]."
usr.cash -= A


Well here is what I did with the code you said would work.

and this is what I get back
Full Moon Fantasy.dm:826:warning: it is recommended that you use an object filter or 'anything' when combining constant input types with lists
Full Moon Fantasy.dm:823:M.client:warning: use of M precedes its definition
Full Moon Fantasy.dm:829:M :warning: definition is here
Full Moon Fantasy.dm:823:M:warning: use of M precedes its definition
Full Moon Fantasy.dm:824:M.name:warning: use of M precedes its definition
Full Moon Fantasy.dm:825:M.name:warning: use of M precedes its definition
Full Moon Fantasy.dm:825:M:warning: use of M precedes its definition
In response to Hellonagol
This is why copying and pasting instead of actually looking at it and learning doesn't get anywhere.

Go back and look at Ter's code. Figure out what it does, and try and implement it yourself.
In response to Kalzar
I will stick with my old code because I actually understand it.
In response to Hellonagol
mob/verb/Give_Cash()
var/list/Choices=new/list()
for(var/mob/M in world)
if(M!=usr)
Choices+=M
var/mob/Mob2Give2=input("Select a Player","Give Cash") as null|anything in Choices
if(Mob2Give2==null) return
//input stuff for amount of money to give
Mob2Give2.money+=money2give


lets try not to confuze people now ter =P
your code is somewhat advanced, and far outside the necesary requirements for something as simple as this lol
In response to Falacy
course u could also do something as simple putting
if(M==usr) return

on the first line of the verb
but what fun would that be =P
In response to Falacy
Uh, right, aside from that thing where I can give negative amount, fractions, and even more money than I have.

Here's how I'd do it:
mob/verb/give_money(mob/M as mob in world.contents-usr,amount as num)   // no need for a for() loop for that!
if(!M || amount <= 0 || money < amount) return // Go straight to jail. Do not pass go. Do not collect $200.
money -= amount
M.money += amount
In response to DivineO'peanut
interestingggggggg
never thought to do that lol
In response to DivineO'peanut
DivineO'peanut wrote:
Uh, right, aside from that thing where I can give negative amount, fractions, and even more money than I have.

Here's how I'd do it:
> mob/verb/give_money(mob/M as mob in world.contents-usr,amount as num) // no need for a for() loop for that!
> if(!M || amount <= 0 || money < amount) return // Go straight to jail. Do not pass go. Do not collect $200.
> money -= amount
> M.money += amount
>


That how I'd do it as well. But that way will let players enter decimals provided that its greater than zero and less than one, and if done correctly, can seriously screw up money. I've had instances with that on my game. So unless he wants decimals like that, you're better off doing amount < 1 rather that amount <= 0. Granted decimals can screw it up anyway, but decimals without a whole number present can do worse damage.
In response to Falacy
If he is too obstinate to learn from it, that's his problem. Not mine. This is an overly simple operation to which I had no intent of making an end-all beat all solution.

Don't mean to be cocky, but I'm in a rush. Anyway, I'll see y'all later tonight.
In response to Ter13
yea or you could just use the round() proc to get rid of the decimals o.o
In response to Falacy
I'm not writing his game for him. That's his responsibility. All I was showing him was all he asked for, how to exclude the user from a list.

Sure, your way is more complete, and more helpful for him later on, but I'm not here to GIVE him all the answers. I'm here to show him a way to do something he specifically asked for.

=/ Or am I just being a jerk? I don't think I am, but I think it's a little pointless to nitpick at me when my snippet answers the question posed, and is correct, and does work.
In response to Ter13
Ter13 wrote:
Or am I just being a jerk?

I don't know, but I do know I am:

mob/verb/give_cash()
//step 1: add all the mobs except for the mobs you don't want (in this case the current player) to a list.
var/list/L = list()
for(var/mob/M in world)
if(M==src) continue //don't add the current player to the list
L+=M

//step 2: provide the player with this list and allow them to select somebody out of it
var/mob/M = input("Give cash","Give cash") as null|anything in L
if(!M) //player clicked "Cancel" or logged out, so return
return 0
...


-- Data
In response to Android Data
lol thats like exactly what i wrote
In response to Falacy
And once again, a less specific example of what I gave him.

He asked how to give money to other players. Yours give it to any mob. Mine actually checks if they are a player.

Second, my snippet wasn't advanced as all.

Associative lists are rudimentary concepts.
input() functions are rudimentary concepts.
for loops are rudimentary concepts.
indentation is a rudimentary concept.
adding and subtracting are rudimentary concepts.
accessing arrays is a rudimentary concept.
creation of variables are rudimentary concepts.

I don't see one complex thing in there at all. You can read a basic BYOND tutorial, or even the first few chapters of the Blue Book, or DM guide and understand all of that.

Maybe I should have taken him through it step by step, but Falacy, your example only removes the associative strings in the lists, and a single if().

If that makes all that much easier to understand, I'll print the blue book, and eat the entire thing.

By your argument, my example is only marginally harder than yours is. Instead of taking issue with me, why not tell him to look at his indentation? Why not ask him what he doesn't understand about it?

So... Yeah, I'm gonna go ask him why he's not understanding my snippet, and try to be helpful.
In response to Ter13
associative lists are definetly harder to understand then just pointing directly to something
and arrays are a pretty basic programming concept, but considering the fact that because byond has a list type variable u practicaly never need to use a real array

so yes, maybe for a C++ programmer these things are "rudimentary" (lol somebody likes big words =P) but for someone using byond it can be a whole lot simpler then that and theres no need to complicate it here

and you could easily add that check for a client into the same if that check if theyre the usr, not all that big of a deal o.O
In response to Hellonagol
What part are you having trouble understanding? I can give you a step by step.


Our example:

give_cash()
var/list/L = list()
for(var/mob/M in world)
if(M.client&&M!=src)
L += M.name
L[M.name] = M
var/choice = input("Give cash","Give cash") as null|anything in L
if(!choice||!L[choice])
return 0
var/mob/M = L[choice]
//add money to the selected player.


First, we need to create a list to store all the players in the world to.

var/list/L = list()


Next, we loop through all the mobs in the world, and check if they have a client, and are not the one who is giving the money. If they have a client, that means they are a player.

for(var/mob/M in world) //loops through every mob in the world
if(M.client&&M!=src)
L += M.name
L[M.name] = M





EXAMPLE

What we actually do, if the mob is a player, and is not the user, is adding to the list.

We are using a special kind of list for this, it's called an Associative list. It associates a string, in this case, the player's name, with a value.

Normally, when accessing a list like this one:

var/list/L = list("jim","bob","tom")

By getting values from their position in the list. I.E.:

L[1] == "jim"
L[2] == "bob"
L[3] == "tom"

But if we want our names to also be associated with their ages in the same list, rather than create a second list, we can just put a second value in the list:

var/list/L = list("jim"=21,"bob"=20,"tom"=40)

This is exactly the same as the last list, when it comes to getting the values, 1, 2, and 3 will all return "jim", "bob", and "tom", but you can get their ages by using the names.

L[1] == "jim"
L[2] == "bob"
L[3] == "tom"
Also:
L["jim"] == 21
L["bob"] == 20
L["tom"] == 40
Therefore:
L[L[1]] == 21
L[L[2]] == 20
L[L[3]] == 40
Associative lists are very good for input() procs, as you can use a human readable string to represent an object, or another piece of data that may be harder for a human to understand in text/numerical form, like a color.




Next, we need to actually allow the player to choose from a list. input() has a nifty little tool you can use to tell the input box what kind of data to expect. This is the 'as' keyword. Since anything can go in a list, BYOND will warn us if we use anything other than 'anything'.

You can list multiple types of data by separating them with a vertical bar '|' (I say 'or', when I read this aloud).

There is another useful type you can add to anything to add a cancel button to your input box: 'null'. This means the player can choose to not answer, and just select cancel instead, returning null.

Note though, that anything must always be the right-most type, meaning null must come before anything.

var/choice = input("Give cash","Give cash") as null|anything in L


Two strings are in this function, text that will be displayed above the list, and text that will be displayed above the title of the input box that pops up.

Also, note the use of the 'in' keyword. This means that you are selecting from a list. In this case, you are selecting from our associative list we made earlier, 'L'.


Next, we have to check if the user selected cancel, or if the player we chose is still in the world, as time can pass between when the list was made, and when the input was answered, and we cannot account for what happens between that.

if(!choice||!L[choice])
return 0


We are forcing the verb to stop running if either value is null.

Remember that choice is a string here, as what we actually selected was something like: "tom", and the value of L["tom"] will actually be equal to tom himself, and not just his name.

And last, we have to just get the mob we chose from the list:

var/mob/M = L[choice]


After this, you just write in your code to give the money to the other players.
In response to Hellonagol
Your error has to do with indentation, not my code not working.
Page: 1 2