mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
I'm in the process of making a game and i'm stuck, mostly im playing around and learning scripting as i go along. What i have is
Code:
on $*:text:/^[!@.]getcash/Si:#:{
  var %getcash = $rand(10,100)
  inc %totalcash %getcash
  msg $chan $nick is given %getcash $+ m $+ , $nick now has %totalcash $+ m
}
What i need is for each individual nick that does [!@.]getcash to save the amount they get to only their nick. So for example if nick1 does !getcash and they end up with 10m it saves that amount to their nick and when nick2 does !getcash and gets 100m it saves that amount to their nick and so on and so forth with it increasing by however much they happen to get when doing !getcash.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You will need to decide on how you want to store the information. Variables are fine, if there aren't many. But you normally want to avoid setting a variable for every nick who plays a game unless the variables are unset afterwards. Instead, you are better off saving the data in another format. For frequently used data, a hash table is a good option. Just be sure to save it as it won't save itself. Or for infrequently used data, you might consider using the INI file format.

Hash Table Save/Load example:
Code:
//hadd Game $nick $+ . Money %totalcash
//echo -a $hget(Game,$nick $+ .Money)


INI Save/Load example:
Code:
//writeini Game.ini $nick Money %totalcash
//echo -a $readini(Game.ini,$nick,Money)


Note that the Hash Table example don't show the need for using /hload and /hsave and /hmake. Also, the Hash Table example stores the "item" as Nick.Money . Depending on what you're doing, you might instead just save it as Nick and then use $gettok() to pull out the specific data from a list of data (money, items owned, etc), or some other setup that works for you.

INI is the easiest to learn, but hash tables offer greater speed in most cases when the data is accessed frequently and can be more flexible to work with.

And, just as an example, here's a variable solution:
Code:
//set %Money. $+ $nick %totalcash
//echo -a $($+(%,Money.,$nick),2)


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2011
Posts: 34
O
Ameglian cow
OP Offline
Ameglian cow
O
Joined: Jan 2011
Posts: 34
I'm wanting to go the variable route because i don't really plan on having a large amount of users. I tried using
Code:
//set %Money. $+ $nick %totalcash
//echo -a $($+(%,Money.,$nick),2)
but it gives me an error. I don't want it to echo me anything anyway. I think this will work but on the msg line it fails to recognize the %totalcash. $+ $nick variable.
Code:
on $*:text:/^[!@.]getcash/Si:#:{
  var %getcash = $rand(10,100)
  inc %totalcash. $+ $nick %getcash
  msg $chan $nick is given %getcash $+ m and now has %totalcash. $+ $nick $+ m 
}

Example:
<@nick1> .getcash
<@me> nick1 is given 65m and now has nick1m

Last edited by ohaithar; 27/04/11 11:06 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Use the format I gave you. Echo was an example. You still need to use the same format for the variable regardless where you use it.


Invision Support
#Invision on irc.irchighway.net
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
You need to evaluate the variable at your last line. That is, add either [ ] evaluation brackets or use the $eval() identifier, or the short form of it: $(), like Riamus2 used above. Note that the "m" must not be included in the evaluation, for it's not part of the dynamic variable's name.
Code:
...and now has $($+(%,totalcash.,$nick),2)  $+ m 


Last edited by Horstl; 27/04/11 11:57 PM.

Link Copied to Clipboard