Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Random Templates?
Random Templates?
2001-11-20, 5:01 PM #1
I tried this:

Code:
	I = Int(Rand()*2) + 1;
	CreateThingAtPosNr(Snow, GetThingSector(Ghost5), GhostPos, '0 0 0');


To randomly create one of 3 templates, but it just crashes...any ideas?
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2001-11-20, 5:19 PM #2
Well, Ive hand more luck just using a limiter. Something a bit like this..


Code:

I = Rand() * 10;
While(I > 3) { I = Rand() * 10; }

Creatething(Snow, Ghost);





 

Simply put, it keeps generating random numbers till it gets one at or below 3. Works fine for me.
[http://www.plauder-smilies.com/spiny.gif]


------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2001-11-20, 5:44 PM #3
It still crashes...I'm using CreateThingAtPosNr, and I can't use create thing..so that's probably why. It's not much of a big deal, just wanted random snowflake sizes [http://forums.massassi.net/html/smile.gif]
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2001-11-20, 5:46 PM #4
And I have to use CreateThingAtPosNr(); since they are created randomly, and sometimes off of the map, so I can't use anything but that.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2001-11-20, 5:51 PM #5
Ok, so modify it a little...

Code:
I = Rand() * 10;
While(I > 3) { I = Rand() * 10; }
CreatethingatposNR(Snow, Getthingsector(Ghost), Ghost, '0 0 0');



Although I dont understand why its crashing.
Put up the whole cog, lets see whats goin on.. [http://www.plauder-smilies.com/happy/wink.gif]



------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2001-11-20, 9:47 PM #6
You probably got the way of using array wrong.

Code:
symbols

template Snow0=my_snow_tpl1 local
template Snow1=my_snow_tpl2 local
template Snow2=my_snow_tpl3 local

end

code

randomed = rand() * 3;
if(randomed == 3) randomed = 2;

CreateThing(Snow0[randomed], Ghost);


There are 2 ways to make arrays.

1.

template Snow1=blah...
template Snow2=blah...
template Snow3=blah...

and get them as "Snow[x]".

2.

template Snow0=blah...
template Snow1=blah...
template Snow2=blah...

and get them as "Snow0[x]".

I take the second method as it can use "Snow0[0]" as the first method doesn't take the "0" as the first array.
(If I remember correctly)

Also I've always been wondering when using randoms that if you create a random number up to 3, for example as "value = rand() * 3".

I think this can go from 0 up to 3. And when inserted into the array number it gets rounded down. But if it gets plain 3, that will get the 4th array element.

But the chance of getting 3 is so small (like they may never even happen), but by any chance if it got 3, the script gets bugged up, as you may have expected to make only 3 templates and such. So, I just put a little fail safe that may be on a real low chance.

Or I may just be caring too much [http://forums.massassi.net/html/smile.gif] 1 in a million chance.

(rand() can be like 0.249237953 and it has to be 1.000000000, oh well.)

------------------
http://millennium.massassi.net/ - Millennium

[This message has been edited by Hideki (edited November 21, 2001).]
2001-11-21, 7:01 AM #7
Nah..it's okay, I decided not to use that. Thanks anyways. Now I need to figure out what flags make an actor un-targetable..
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2001-11-21, 2:21 PM #8
A few notes:
1) If it's anything like other random number seeds that I've used (which it is), if you multiply it by 3 it will generate between 0 and 3, but it will never actually be 3. To generate from 1 to 3 (where 1 and 3 are possible), you would do something along the lines of randomed = rand() * 3 + 1;

2) Array support in cog is extremely limited. Not really a note, more of a question (or confirmation): Multi-dimensional arrays aren't possible, are they?
2001-11-21, 3:51 PM #9
Emon - The reason your first cog is crashing is because you have ...

Snow in your Create Thing Verb

It need to be ...

Snow0

You missed out the "0" and thats what's making JK crash becasue the array is invalid.

2001-11-21, 7:12 PM #10
Aglar, I think rand() does return 1.0000 as well, doesn't it?

And if you do "rand() * 3 + 1", it goes from 1 to 4 (or 4 not including, if rand() can never be 1).

Someone can check in jk by this by just borrowing the little space in the startup of kyle.cog.

Code:
while(rand() != 1) print "still trying...";
print "rand() made it as 1!"


Now, it may freeze, but who knows.

------------------
http://millennium.massassi.net/ - Millennium

[This message has been edited by Hideki (edited November 21, 2001).]
2001-11-21, 7:15 PM #11
Yes, Rand() wil return a 1.00000, but VERY rarely. But it does happen, and one has to account for it.

------------------
Success is the inverse relationship between effort, gain, and loss.
And when the moment is right, I'm gonna fly a kite.
2001-11-22, 1:31 AM #12
In that case you could check if it's 1 and if so knock it down to what you need the highest value to be.
2001-11-22, 4:00 AM #13
Of course its not as pretty but you could always do:
Code:
NUMBER = Rand();

if(NUMBER <= 0.33)
{
CreateThingAtPosNr(Snow1, GetThingSector(Ghost5), GhostPos, '0 0 0');
Return;
}

if(NUMBER <= 0.66)
{
CreateThingAtPosNr(Snow2, GetThingSector(Ghost5), GhostPos, '0 0 0');
Return;
}

if(NUMBER <= 1)
{
CreateThingAtPosNr(Snow3, GetThingSector(Ghost5), GhostPos, '0 0 0');
Return;
}

Return;


[This message has been edited by The_New_Guy (edited November 22, 2001).]
- Wisdom is 99% experience, 1% knowledge. -
2001-11-22, 8:19 AM #14
Yeah, I just thought of that. Thanks guys.
Bassoon, n. A brazen instrument into which a fool blows out his brains.

↑ Up to the top!