Prowler Productions
  Dink Smallwood Forum
  Trying to get a random-number-order script to work

Post New Topic  
profile | register | faq

Author Topic:   Trying to get a random-number-order script to work
Tamtur posted 05-27- 04:07 PM CT (US)   Click Here to See the Profile for Tamtur   Click Here to Email Tamtur  
Boy, this flashcard thing is harder than I thought! Maybe I should just write them out on paper :).
Anyway, I have a script wrote out that is *supposed* to put out the numbers 1-12 in random order. Anyway, at least it's spitting out numbers now - and they're between 1 and 12 - but the last time I ran it 8 of the numbers were 6! It's pretty long (and confusing), but here it is if you have time. If you know of an easier way to do it, I'm all ears!!

Info: &01word, &02word, etc are all global variables, as is &track and &myrnd
&total, &work, and &rndword are initted in the main ( void ) procedure
&work is just to let me know how many loops its taking

void click ( void )
{
debug ("starting nums are &01word, &02word, &03word, &04word");
debug ("&05word, &06word, &07word, &08word");
debug ("&09word, &10word, &11word, &12word");

&rndword = random(12,1);
&01word = &rndword;
say_xy("first num is &01word", 40, 100);

&total = &01word;
&track = 2;
&work = 1;

Loop:
&rndword = random(12,1);
if (&rndword = &01word)
{
&work += 1;
goto loop;
}
if (&track == 2)
{
&02word = &rndword;
&total += &02word;
say_xy("second num is &02word", 40, 110);
track();
}
if (&rndword = &02word)
{
&work += 1;
goto loop;
}
if (&track == 3)
{
&03word = &rndword;
say_xy("third num is &03word", 40, 120);
&total += &03word;
track();
}
if (&rndword = &03word)
{
&work += 1;
goto loop;
}
if (&track == 4)
{
&04word = &rndword;
&total += &04word;
say_xy("fourth num is &04word", 40, 130);
track();
}
if (&rndword = &04word)
{
&work += 1;
goto loop;
}
if (&track == 5)
{
&05word = &rndword;
&total += &05word;
say_xy("fifth num is &05word", 40, 140);
track();
}
if (&rndword = &05word)
{
&work += 1;
goto loop;
}
if (&track == 6)
{
&06word = &rndword;
&total += &06word;
say_xy("sixth num is &06word", 40, 150);
track();
}
if (&rndword = &06word)
{
&work += 1;
goto loop;
}
if (&track == 7)
{
&07word = &rndword;
say_xy("seventh num is &07word", 40, 160);
&total += &07word;
track();
}
if (&rndword = &07word)
{
&work += 1;
goto loop;
}
if (&track == 8)
{
&08word = &rndword;
&total += &08word;
say_xy("8th num is &08word", 40, 170);
track();
}
if (&rndword = &08word)
{
&work += 1;
goto loop;
}
if (&track == 9)
{
&09word = &rndword;
&total += &09word;
say_xy("ninth num is &09word", 40, 180);
track();
}
if (&rndword = &9word)
{
&work += 1;
goto loop;
}
if (&track == 10)
{
&10word = &rndword;
&total += &10word;
say_xy("10th num is &10word", 40, 190);
track();
}
if (&rndword = &10word)
{
&work += 1;
goto loop;
}
if (&track == 11)
{
&11word = &rndword;
say_xy("11th num is &11word", 40, 200);
&total += &11word;
&12word = 78;
&12word -= &total;
&total += &12word;
say_xy("12th num is &12word", 40, 210);
debug("final scores are &01word, &02word, &03word, &04word");
debug ("&05word, &06word, &07word, &08word");
debug ("&09word, &10word, &11word, &12word");
debug ("total is &total, work is &work");
&myrnd = 1;
&track = 1;
}

}

void track ( void )
{
&track += 1;
goto loop;
}

I included it all in case anyone got ambitious and wanted to try it out.

All you'd have to do is attach it to one of the buttons on the main dink screen (in start.c) and add a main proc that initted the variables and turned it into a button.

Please, please, please help, I don't know what else to try to get the bugs worked out.

Thank you

FF4LIFE posted 05-28- 03:08 AM CT (US)     Click Here to See the Profile for FF4LIFE  Click Here to Email FF4LIFE     
Eh, to tell you the truth, i have no clue.
But on a somewhat related note, i'm trying to have a spell cast on all enemies on the screen, and i can get it to choose a random sprite of all the brains i want, but how do i choose ALL the sprites, because get_sprite just gets the same one each time, and get_random_sprite does random, so is there a way to say get_next_sprite or something clever like that?

Also, not related at all, I'm having some math troubles...I have one global thats going to detect a lot of things, basicly, &items = 987654321
this means i have 9 of item#1, 8 of item#2, and so on. So now i have to disect it...and the math isn't working...lets make it just 32, and try to get the three out of it, seperate from the 2...i did this, and it should work:

int &bomb = &items/10;
int &crap = &bomb*10;
int &potion = &items -= &crap;

so....&bomb should return as 3, right, 32/10 is about 3, and i heard somewhere it rounds down....maybe not....but then multiply the 3 * 10, so 30, and subtract from 32 and you get 2...right?

WRONG!!!

HELP!!!

Drakeman posted 05-28- 11:56 PM CT (US)     Click Here to See the Profile for Drakeman  Click Here to Email Drakeman     
Try

int &potions = &items;
&potions -= &bomb;

That is split up the ne line into two commands. I don't think DinkC supports mutlitiple math commands on one line.

redink1 posted 05-29- 06:46 PM CT (US)     Click Here to See the Profile for redink1  Click Here to Email redink1     
For the flash-card thing, I did something similar for my D-Mod currently in production (for a year or two) You Don't Know Dink. This is what I did (all of the vars are global (unless int) and were loaded so &question was last, so a bug wouldn't happen):

void main(void)
{
retry:
wait(1);
&question = random(10,1);
if (&question == &question1)
{
goto retry;
}
if (&question == &question2)
{
goto retry;
}
if (&question == &question3)
{
goto retry;
}
if (&question == &question4)
{
goto retry;
}
if (&question == &question5)
{
goto retry;
}
if (&question == &question6)
{
goto retry;
}
if (&question == &question7)
{
goto retry;
}
if (&question == &question8)
{
goto retry;
}
if (&question == &question9)
{
goto retry;
}
if (&question1 == 0)
{
&question1 = &question;
goto start;
}
if (&question2 == 0)
{
&question2 = &question;
goto start;
}
if (&question3 == 0)
{
&question3 = &question;
goto start;
}
if (&question4 == 0)
{
&question4 = &question;
goto start;
}
if (&question5 == 0)
{
&question5 = &question;
goto start;
}
if (&question6 == 0)
{
&question6 = &question;
goto start;
}
if (&question7 == 0)
{
&question7 = &question;
goto start;
}
if (&question8 == 0)
{
&question8 = &question;
goto start;
}
if (&question9 == 0)
{
&question9 = &question;
goto start;
}
if (&question10 == 0)
{
&question10 = &question;
goto start;
}
start:
//Each line has to be a maximum of 40 characters (including spaces)
if (&question == 1)
{
&points = 1000;
&correct = 1;
&question_1 = say_xy("In Dink Smallwood, the King plays a", -110, 100);
&question_2 = say_xy("rather important part.",-110,120);
&question_3 = say_xy("What is the King's name?",-110,140);
&line1 = say_xy("1. King Daniel",-110,190);
&line2 = say_xy("2. King Lucifer",-110,210);
&line3 = say_xy("3. King Gordon",-110,230);
&line4 = say_xy("4. King Pap",-110,250);
}

And do something like if (&question == 2) and such for the rest of the parts, and of course you'll have to modify it for 12 items. It works, though.

redink1 posted 05-29- 07:04 PM CT (US)     Click Here to See the Profile for redink1  Click Here to Email redink1     
I suppose I should've read FF4Life's post before I dismissed it right away for not pertaining to Tamtur's :)

Actually, I've been working on something similar to storing other variables in one SuperVar (my dubbing for it). Anyway, if you want to see how I got it to work, dowload it at http://www.3ddownloads.com/?file_id=147389 . Its only 390 bytes, so it should download fast :)

Note 1, you do have to start from the left of the variable and go all the way down to the variable that you want. So, if &supervar is 987654321, and you want to find out what 3 is, you have to calculate at least the &carry for the 987654 part of it.

Note 2, for reasons unknown, in my experimentation with SuperVars, they will generally output correct values the first time they are run (like in an item script). However, the second time they are run, the values are not correct. I think the problem is int local variables over and over, but I haven't found an exact solution so far.

Drakeman posted 05-29- 09:58 PM CT (US)     Click Here to See the Profile for Drakeman  Click Here to Email Drakeman     
Ummm make that second line...

&potions -= &crap;

I wish you could see the message you were replying to in this forum

FF4LIFE posted 05-29- 11:05 PM CT (US)     Click Here to See the Profile for FF4LIFE  Click Here to Email FF4LIFE     
Hey, thanks a bunch. Yeah if that doesn't work i'll take out the multiple commands, tho i thought those worked...myabe not..thanks.
Tamtur posted 05-31- 12:05 PM CT (US)     Click Here to See the Profile for Tamtur  Click Here to Email Tamtur     
Thanks Redink, I never did figure out what was wrong with my script, but it works now with your suggestions.

Much appreciated

redink1 posted 06-01- 07:53 PM CT (US)     Click Here to See the Profile for redink1  Click Here to Email redink1     
Tamtur, I thought of a way to make my script much more streamlined. Hopefully, this will make the script a little bit less unruly (note that &question1 is set within the question part itself):

void main(void)
{
retry:
wait(1);
&question = random(10,1);
if (&question == &question1) goto retry;
if (&question == &question2) goto retry;
if (&question == &question3) goto retry;
if (&question == &question4) goto retry;
if (&question == &question5) goto retry;
if (&question == &question6) goto retry;
if (&question == &question7) goto retry;
if (&question == &question8) goto retry;
if (&question == &question9) goto retry;
//Each line has to be a maximum of 40 characters (including spaces)
if (&question == 1)
{
//Set &question1 to &question!
&question1 = &question;
&points = 1000;
&correct = 1;
&question_1 = say_xy("In Dink Smallwood, the King plays a", -110, 100);
&question_2 = say_xy("rather important part.",-110,120);
&question_3 = say_xy("What is the King's name?",-110,140);
&line1 = say_xy("1. King Daniel",-110,190);
&line2 = say_xy("2. King Lucifer",-110,210);
&line3 = say_xy("3. King Gordon",-110,230);
&line4 = say_xy("4. King Pap",-110,250);
}

//Etc.

Tamtur posted 06-03- 01:08 PM CT (US)     Click Here to See the Profile for Tamtur  Click Here to Email Tamtur     
Hey thanks, redink, that does look a lot better.

Post New Topic  Post Reply
Hop to:


Contact Us | Prowler Productions

Powered by: Ultimate Bulletin Board, Freeware Version 5.10a
Purchase our Licensed Version- which adds many more features!
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 2000.