Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-17-2012, 03:59 AM
Fysez Fysez is offline
Banned
Join Date: Apr 2012
Posts: 89
Fysez has a little shameless behaviour in the past
Randomizing?

So, I've been trying to work with making words/ect random.
I understand how to make numbers randomize, But it seems
I cannot figure out other things like words.

What I have an tried to do, Did not work:

PHP Code:
function onPlayerTouchsMe() {
this.chat1 "Hey";
  
this.chat2 "Hi";
  
this.chat3 "How";
  
this.chat4 "Are";
  
this.chat5 "You";
  
this.chat6 "To";
  
this.chat7 "Day?";
  
this.speech this.chat(int(random(1,8)));
  
this.chat this.speech;

Please help and teach me how I can fix this?

Last edited by Fysez; 07-17-2012 at 04:06 AM.. Reason: Spelling Error
Reply With Quote
  #2  
Old 07-17-2012, 05:24 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Your code doesn't make any sense. this.chat isn't a function. How would it know that what you really want is to append the random number to "this.chat" and read the value of that variable?

The best way is to just make an array.

PHP Code:
function onPlayerTouchsMe() {
  
temp.chats = {
    
"Hey",
    
"Hi",
    
"How",
    
"Are",
    
"You",
    
"To",
    
"Day?"
  
};
  
  
this.chat temp.chats[int(random(0temp.chats.size()))];

Somebody will probably post below me and point out that you can sort of use randomString, so let me say preemptively to avoid that; it's not intended for arrays and has some pretty big issues when used with them.
__________________
Reply With Quote
  #3  
Old 07-17-2012, 05:42 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Quote:
Originally Posted by cbk1994 View Post
Somebody will probably post below me and point out that you can sort of use randomString, so let me say preemptively to avoid that; it's not intended for arrays and has some pretty big issues when used with them.
It might not have been created with the use of arrays in mind, but the only associated issue with it that I'm aware of is that it requires more than one element to return a value - something Stefan supposedly has fixed.


Quote:
Originally Posted by Stefan View Post
Ok will fix that behaviour of randomstring(), it was originally not made for getting arrays as input.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #4  
Old 07-17-2012, 05:54 AM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
Quote:
Originally Posted by cbk1994 View Post
Somebody will probably post below me and point out that you can sort of use randomString
i think we should play the lottery together
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #5  
Old 07-17-2012, 05:55 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by xXziroXx View Post
It might not have been created with the use of arrays in mind, but the only associated issue with it that I'm aware of is that it requires more than one element to return a value - something Stefan supposedly has fixed.
Seems to be working now. Good catch, I never noticed it was fixed.

I would probably avoid it clientside for the time being, I'm guessing it's still broken in v5.
__________________
Reply With Quote
  #6  
Old 07-17-2012, 02:31 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Try something like this:

PHP Code:
function onPlayerTouchsMe() {
  
this.word1 "Hey";
  
this.word2 "Hi";
  
this.word3 "How";
  
this.word4 "Are";
  
this.word5 "You";
  
this.word6 "To";
  
this.word7 "Day?";
  
this.speech this.word int(random(1,7)+0.5);
  
this.chat this.speech;

I think that's what you need. Or maybe it was this?
PHP Code:
this.word(@ int(random(1,7)+0.5)); 
I switched this.chat# with this.word# just to be on the safe side. I try to avoid getting custom variables mixed up with built-in variables.

Edit: The array approach looks a lot cleaner though. I must have missed cbk's post. Use that method instead.
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #7  
Old 07-17-2012, 02:35 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Quote:
Originally Posted by Jiroxys7 View Post
Try something like this:

PHP Code:
function onPlayerTouchsMe() {
  
this.word1 "Hey";
  
this.word2 "Hi";
  
this.word3 "How";
  
this.word4 "Are";
  
this.word5 "You";
  
this.word6 "To";
  
this.word7 "Day?";
  
this.speech this.word int(random(1,7)+0.5);
  
this.chat this.speech;

I think that's what you need. Or maybe it was this?
PHP Code:
this.word(@ int(random(1,7)+0.5)); 
I switched this.chat# with this.word# just to be on the safe side. I try to avoid getting custom variables mixed up with built-in variables.

Edit: The array approach looks a lot cleaner though. I must have missed that post. Use that method instead.
This is alright to do if you are learning how to use variables, but should never be done like that. Look at Chris's post.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #8  
Old 07-17-2012, 06:48 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Jiroxys7 View Post
Try something like this:

PHP Code:
function onPlayerTouchsMe() {
  
this.word1 "Hey";
  
this.word2 "Hi";
  
this.word3 "How";
  
this.word4 "Are";
  
this.word5 "You";
  
this.word6 "To";
  
this.word7 "Day?";
  
this.speech this.word int(random(1,7)+0.5);
  
this.chat this.speech;

I think that's what you need. Or maybe it was this?
PHP Code:
this.word(@ int(random(1,7)+0.5)); 
I switched this.chat# with this.word# just to be on the safe side. I try to avoid getting custom variables mixed up with built-in variables.
Neither of these are going to work anyway. With the first, you're appending the random number to the value of this.word, which is undefined, and then saying it. If you wanted to append to the variable name, you'd want to do...

PHP Code:
this.chat this.(@ "word" int(random(18))); 
The second will not work either, this.word is not a function, but you're treating it like one.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.