sc2c.org

Go Back   Sc2C.org > Developer's Corner > Scripting
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 08-12-2010, 06:59 PM   #1
pinzu
Junior Member
 
Join Date: Jul 2010
Posts: 8
Default Random PooL help?

if I have a bunch of string stored.

string[1], string[2], string[3] and so on....

and I want a pool with these strings (unused strings).

then I want to assign a random string from the pool, and removing it from the pool.

and still being able to assign new strings at any time.

and a way to readd them to the pool.



I hope that made any sense, anyway, how would I go about making this?
pinzu is offline   Reply With Quote
Old 08-13-2010, 12:23 AM   #2
Ammorth
I blink therefore I am
 
Ammorth's Avatar
 
Join Date: Apr 2010
Posts: 65
Default

You need a string array of strings and an integer to count the number of strings (starts at 0). When you add a string, add the string to the count index (first is 0) and increment the count index. To pick a random string, Rand(0, Count-1). To remove, decrease count by one and swap swap the string at Count with the string at the index you are removing.
__________________
Ammorth is offline   Reply With Quote
Old 08-13-2010, 03:18 AM   #3
pinzu
Junior Member
 
Join Date: Jul 2010
Posts: 8
Default

in theory I think im following, but making it is a entire diffrent thing sadly.

I'll have to keep thinking on the path you guided me too. but a short example would be great if you could spare some time for little me
pinzu is offline   Reply With Quote
Old 08-13-2010, 09:47 AM   #4
Ammorth
I blink therefore I am
 
Ammorth's Avatar
 
Join Date: Apr 2010
Posts: 65
Default

I was rushed for work when I wrote that, otherwise I would have included an exmaple:

Code:
int pool_Count = 0 // start with no strings in the pool string pool_Values[32] // maximum number of elements the pool can hold. Increase or decrease to your needs. // void pool_addString(string toAdd) // takes a string to add to the pool and adds it. // does not check for overflowing the pool // does not return if it failed or succeed void pool_addString(string toAdd) { pool_Values[pool_Count] = toAdd; pool_Count++; } // string pool_getRandom(void) // returns a random string in the pool // does not check for empty pools // removes the string from the pool string pool_getRandom(void) { int temp = RandomInt(0, pool_Count - 1); string out = pool_Values[temp]; pool_Count--; pool_Values[temp] = pool_Values[pool_Count]; return out; }
__________________
Ammorth is offline   Reply With Quote
Old 08-13-2010, 01:58 PM   #5
pinzu
Junior Member
 
Join Date: Jul 2010
Posts: 8
Default

hmm, i sort-of understand direct coding but can't write it myself.
It's funny how you make the biggest break throughs while doing some thing else, showers are awsome! ;D

Here is my solution so far, maybe you can look at it and have a say?

SETUP TRIGGER
Events
Game - Map initialization
Local Variables
setup_intiger = 0 <Integer>
loop_intiger = 0 <Integer>
Conditions
Actions
------- SUPER EASY WORDS --------
------- setup intiger 1-5
------- I know I really dont need "the setup_intiger" but it is for easily removing words in the future without having to re-arrange everything. and the custom script is easier to mass edit...
Variable - Set setup_intiger = (setup_intiger + 1)
General - Custom Script: gv_words[lv_setup_intiger] = "ok";
Variable - Set setup_intiger = (setup_intiger + 1)
General - Custom Script: gv_words[lv_setup_intiger] = "is";
Variable - Set setup_intiger = (setup_intiger + 1)
General - Custom Script: gv_words[lv_setup_intiger] = "to";
Variable - Set setup_intiger = (setup_intiger + 1)
General - Custom Script: gv_words[lv_setup_intiger] = "be";
Variable - Set setup_intiger = (setup_intiger + 1)
and so on....

then;

Another trigger

Actions
Variable - Set Local_RDM_Word = (Random integer between 1 and 10)
General - If (Conditions) then do (Actions) else do (Actions)
If
Word_used[Local_RDM_Word] == false
Then
Unit - Create 1 Drone for player 1 at (Center of Region 001) using default facing (No Options)
Unit Group - Add (Last created unit) to UNIT_GROUP
Unit - Set (Last created unit) custom value 0 to (Real(Local_RDM_Word))
UI - Display (Text(Words[Local_RDM_Word])) for (All players) to Subtitle area
UI - Display (Text(Local_RDM_Word)) for (All players) to Subtitle area
Variable - Set Word_used[Local_RDM_Word] = true
ElseAnother
UI - Display "re-running!" for (All players) to Subtitle area
Trigger - Run (TRIGGER AGAIN) (Check Conditions, Wait until it finishes)

basically it re-runs if the word is in use until it reaches overflow, when all strigs are used. (that shouldn't be a problem) The only problem would be that it runs too many times or that it could be fewer.


Im trying to make a qwerty warriors type of map if you are curious.

Last edited by pinzu : 08-13-2010 at 02:40 PM.
pinzu is offline   Reply With Quote
Old 08-13-2010, 05:16 PM   #6
Ammorth
I blink therefore I am
 
Ammorth's Avatar
 
Join Date: Apr 2010
Posts: 65
Default

There is a chance looping randomly like that will cause the script to stop (as it runs for too long). I would look at removing the word (as I demonstrated above) to solve that.
__________________
Ammorth is offline   Reply With Quote
Old 08-13-2010, 11:05 PM   #7
pinzu
Junior Member
 
Join Date: Jul 2010
Posts: 8
Default

how long are we talking about here? ;O

next trouble; should there be diffrent difficulty levels and any suggestions on how to scale the difficulty depending on how long you survive.
I dont expect to get any help but dang, its really hard
pinzu is offline   Reply With Quote
Old 08-13-2010, 11:07 PM   #8
Ammorth
I blink therefore I am
 
Ammorth's Avatar
 
Join Date: Apr 2010
Posts: 65
Default

you could have an upgrade the slowly increases damage and health of the enemy and research them as you go. The game would go harder over time.

If you are unlucky, it could loop infinitely. Its highly unlikely, but there is still a chance.
__________________
Ammorth is offline   Reply With Quote
Old 08-15-2010, 09:22 AM   #9
JademusSreg
Laughs Derisively
 
JademusSreg's Avatar
 
Join Date: Apr 2010
Posts: 112
Default

It could possibly approach infinite, but it will eventually hit the op limit.
__________________
Seek always to excel in whatever you do.
My sense of value is redshifted.
JademusSreg is offline   Reply With Quote
Old 08-16-2010, 02:47 AM   #10
pinzu
Junior Member
 
Join Date: Jul 2010
Posts: 8
Default

okey, I got some help from Xackery on the issue however, he created only the random function.

WordList = "" <String[99]>
WordListStartMax = 99 <Integer>
WordListCurMax = 0 <Integer>

Setup
Game - Map initialization
x = 0 <Integer>
Visibility - Create a visibility revealer for player 1 within (Entire map)
Variable - Set WordListCurMax = WordListStartMax
General - For each integer x from 0 to 99 with increment 1, do (Actions)

GetRandomWord
Options: Function
Return Type: String
Parameters
Grammar Text: GetRandomWord()
Hint Text: (None)
Custom Script Code
Local Variables
curIndex = 0 <Integer>
curWord = "" <String>
x = 0 <Integer>
Actions
Variable - Set curIndex = (Random integer between 0 and WordListCurMax)
Variable - Set curWord = WordList[curIndex]
General - For each integer x from WordListCurMax to (WordListStartMax - 1) with increment 1, do (Actions)
Actions
Variable - Set WordList[x] = WordList[(x + 1)]
Variable - Set WordListCurMax = (WordListCurMax - 1)
General - Return curWord

the second part is attaching the word to a unit and a text tag. (and the other way around) Most importantly being able to re-add the world to the list.

GetWord
Events
Game - Player Any Player types a chat message containing "drone", matching Exactly
Local Variables
Conditions
Actions
Unit - Create 1 Drone for player 1 at (Random point in Region 001) using default facing (No Options)
Text Tag - Create a text tag with the text (Text((GetRandomWord()))) for (All players), using a font size of 24, at (Position of (Last created unit)) and height offset 1.0, initially Visible, and fog of war enforcement set to false

Last edited by pinzu : 08-17-2010 at 04:44 AM.
pinzu is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 10:59 PM.


Powered by vBulletin
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.