Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Help with random texts (https://forums.graalonline.com/forums/showthread.php?t=81302)

Switch 08-18-2008 12:22 AM

Help with random texts
 
Trying to test my GUI skills, since I haven't for a LONG time.
So I have a confirmation code that is supposed to come out random from 3 sets of letters/numbers. I have all of those as this.beg, this.mid, this.end and I set up the temp.confCode as follows
PHP Code:

temp.confCode int(random(this.beg11)) @ int(random(this.mid9)) @ int(random(this.end11)); 

When I go on player and try to use it, the GUI comes up and everything's fine, but it's coming out as numbers.
One example is "035"
How can I get it to display as TEXT?

And on a side note:
How do I set text to save as a log/*.txt file from a serverside script?

napo_p2p 08-18-2008 12:37 AM

If I remember correctly, random(start, end) will only return a random number within [start, end)

It's a bit different to generate a random character. Here's one way to generate a random upper-case letter:
PHP Code:

char(int(random(6591))); 

You can look at an ascii table to see where I get the 65 and 91 from. You could also look at an ascii table to get the ranges for lower-case letters.

Or, you could predefine an array of all the characters you want to include in your random strings, then use randomstring().
Example:
PHP Code:

temp.chars = {"A""B""C""D""a"123};  //Put all characters in here.
temp.confCode randomstring(temp.chars) @ randomstring(temp.chars) @ randomstring(temp.chars); 

And, to save as a log/*.txt file you can use savelog2
Example:
PHP Code:

savelog2("snaps.txt""The boy bought the basketball"); 


Switch 08-18-2008 01:04 AM

Quote:

Originally Posted by napo_p2p (Post 1415326)
If I remember correctly, random(start, end) will only return a random number within [start, end)

It's a bit different to generate a random character. Here's one way to generate a random upper-case letter:
PHP Code:

char(int(random(6591))); 

You can look at an ascii table to see where I get the 65 and 91 from. You could also look at an ascii table to get the ranges for lower-case letters.

Or, you could predefine an array of all the characters you want to include in your random strings, then use randomstring().
Example:
PHP Code:

temp.chars = {"A""B""C""D""a"123};  //Put all characters in here.
temp.confCode randomstring(temp.chars) @ randomstring(temp.chars) @ randomstring(temp.chars); 

And, to save as a log/*.txt file you can use savelog2
Example:
PHP Code:

savelog2("snaps.txt""The boy bought the basketball"); 


Ah, thanks a lot :D
++rep if i could. gotta spread :(

edit: I did temp.confCode=randomString(this.beg) etc., and it didn't work.
It shows up as blank in the GUI.

napo_p2p 08-18-2008 02:09 AM

Quote:

Originally Posted by Switch (Post 1415331)
edit: I did temp.confCode=randomString(this.beg) etc., and it didn't work.
It shows up as blank in the GUI.

What is in this.beg?

randomstring() takes in an array of strings and outputs a random element.

Switch 08-18-2008 02:10 AM

PHP Code:

  this.beg = { "iA""Pq""oa""cQ""Vu""zC""Gd""jE",
    
"aT""fg""io""mv" };
  
this.mid = { 123456789};
  
this.end = { "io""vb""cH""pA""oA""oa""ua""Ac",
    
"iA""Co""Op""In" }; 

That's all the arrays I'm using.

Edit:
Found the problem!
Had to use thiso.confCode inside of the GuiMLTextCtrl, and put the randomize setter outside of the GUI.

[email protected] 08-21-2008 12:12 AM

just so its out there, you can also savelog2 folder types [always give the NPC server additional rights though!]

savelog2("items/hugeasslog.txt", "wurr");
savelog2("staff/xAndrewx", "hot damn");

etc


All times are GMT +2. The time now is 04:35 AM.

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