Black-Cell.net

  • June 22, 2018, 12:10:13 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: Dynamic array sizes and the renegade API  (Read 2535 times)

Reborn

  • Donator
  • Offline Offline
  • Posts: 200
    • View Profile
Dynamic array sizes and the renegade API
« on: February 12, 2008, 01:08:02 PM »

I was thinking to myself it would be nice to create a script that chooses one of several cinematic files to attach to an object in conjunction with test_cinematic.
I was thinking of adding a spawner to a map that created a signal flare, and attach the script (for instance) "reb_random_cinematic" to the flare, the cinematic files would be a chin00k dropping off a power-up by parachute. And I could create several cinematic files, each dropping off a different power-up. This was something I was thinking of to replace the current random weapon spawns. For me I wouldn't really need to array to be set in size dynamically, I could just hard-code the array to list the cinematic files then choose one from random.

I thought it might be nice for others to use aswell, but it occured to me that not everyone would want to use the same amount of cinematic files, and it would be extremely un-likely that everyone would want to name there cinematic files the same as mine.
So although the script would be useful for my one indulgence, other then that it would be pretty useless.

I started thinking it would be nice to be able to attach the script to the object in level edit, then define how many cinematic files you want to attach to it and there names. But is this even possible?
I can see how I would do it if the amount of cinematic files was always going to be a fixed value of 1,2,3,4,5... etc etc, but how would you actually do this if you wanted it more dynamic then that?

My first thought would work I think, have an input parameter define an interger variable, say x. Then crate some huge ass list like:

if(x == 1){
//array here with 1 input parameter for the cinematic file name
}
else if (x == 2){
//array here with 2 input parameters for the cinematic file names
}
etc etc....
However that seems to be a rather dumb-ass way of doing it.

Not really a big deal, but I just felt my mind open a little when exploring the idea and I am interested in seeing how you might tackle it.
I love these moments.
« Last Edit: February 12, 2008, 01:25:59 PM by Reborn »
Logged

lizard175

  • Offline Offline
  • Posts: 559
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #1 on: February 12, 2008, 01:58:33 PM »

if you want to stick to your first thought, make the array size x and make a loop 0..x-1 which asks for input x times.

you could always make it a vector or arraylist if you don't want to make them declare the size from the start. in which case you use a while loop until they input something like "done" or an empty string, your choice.
Logged
ALL YOUR CAPS LOCK ARE BELONG TO US

mylumnad

  • Renegade Server Moderator
  • Offline Offline
  • Posts: 1402
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #2 on: February 12, 2008, 02:00:53 PM »

LIZARD!!!!!!!!!!!!!!!!!
Logged

Reborn

  • Donator
  • Offline Offline
  • Posts: 200
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #3 on: February 12, 2008, 02:23:06 PM »

OK, let me explain myself a little better.

Say I want to to allow the user in level edit to define how many elements are in the array. So they use an integer input parameter which I will call x.

So I have something that looks like:

Code: [Select]
int x = input_parameter; //can't remember the syntax for input parameters off the top of my head.
char cinematic_array[[b]x[/b]];


So say they decide they want to define 100 elements, they have 100 cinematic files they wish to be choosen at random. so x = 100.

I would now need level edit to generate 100 input parameters for them to fill in.

Code: [Select]
cinematic_array[0] = input_parameter1; // again, forgotten input_parameter syntax for level edit users.
cinematic_array[1] = input_parameter2;


or perhaps rather some for loop to set the elements values.

Code: [Select]
for(int i = 0; i < x; i++){
cinematic_array[i ] = input_parameter /* (some increasing number here too)*/;
}
etc etc

My problem is not so much creating a dynamically sized array I guess, but more a case of dynamically generating a way for level edit to list the amount of input parameters for the elements in the array. Is it possible?
« Last Edit: February 12, 2008, 02:29:30 PM by Reborn »
Logged

Reborn

  • Donator
  • Offline Offline
  • Posts: 200
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #4 on: February 12, 2008, 04:23:35 PM »

Code: [Select]
void reb_random_cinematic::Created(GameObject *obj){

const char *cinematic_name;
int x;
cinematic_name = Get_Parameter("Cinematic_name");

x = Get_Int_Parameter("Number_Of_Cinematics");

char cinematic_array[x];

for(int i = 0; i < x; i++){
cinematic_array[i] = cinematic_name;
}

Maybe now you can see the problem? That loop would set all elements of the array to whatever the user in Level Edit defined as "Cinematic_name", to allow for more then one cinematic I would need "cinematic_name2, cinematic_name3 etc etc and have each of them get a different Parameter so it listed in level edit's drop down menu. I need to find a way to generate x amount of "cinematic_name = Get_Parameter("Cinematic_name");" but increase the String and variable name by one each time until it gets to x.



}
Logged

deathdish

  • Offline Offline
  • Posts: 925
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #5 on: February 12, 2008, 11:07:01 PM »

I don't see what your problem is, I'll write what I see with that code

You make a string, and an integer representing number of strings.
You input some rubbish into the string, (call it "abcde" for the moment)
You input number of parameters, (make it 5 for now)
then you declare the array with 5 as number of elements (just wondering, is this allowed? or should you allocate memory to it? I'm not sure if you can go char ...[<variable>], probably I'm wrong)
then you assign cinematic_array[0], cinematic_array[1], cinematic_array[2], cinematic_array[3], cinematic_array[4] with "abcde"

wait, methinks I found a problem. (tbh, after typing the last few lines lol)

cinematic_name, "abcde" is a string right?
cinematic_array[5] is a string of characters right?
Then how the heck are you going to assign strings into a string of characters? Do you need a 2D array?
Logged

Reborn

  • Donator
  • Offline Offline
  • Posts: 200
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #6 on: February 13, 2008, 07:54:51 AM »

The problem is, I don't want to set each element to the same one single input from the user. What's the point of creating the array (from which later I will choose one element at random to play) if every element is exactly the same?

My problem is generating x amount of unique input parameters for the user to fill out in level edit.

So say I had a use input that they had 20 cinematic files that they wanted to list as possible ones to play, then I would need to have:


const char *cinematic_name1 = Get_Parameter("Cinematic_name1");
const char *cinematic_name2 = Get_Parameter("Cinematic_name2");
const char *cinematic_name3 = Get_Parameter("Cinematic_name3");
const char *cinematic_name4 = Get_Parameter("Cinematic_name4");
const char *cinematic_name5 = Get_Parameter("Cinematic_name5");
etc etc etc
const char *cinematic_name20 = Get_Parameter("Cinematic_name20");

I can't assign each element to the same variable, as then the level edit user would just be presented with one box for inputting the cinematic file name, and then that would be the only one with a chance of being called. Each input parameter needs to be unique.

Don't worry about it, I was only interested to see if it could be done. For my purposes I know exactly how many cinematics I want to use and can hard code the entire lot. I was just going to be helpful and see if I coudl adapt it for others to use.
Logged

deathdish

  • Offline Offline
  • Posts: 925
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #7 on: February 13, 2008, 08:31:58 AM »

how about the problem with assigning a character with a string? :P

So you want heaps of cinematic names right? Let me try...

Code: [Select]
void reb_random_cinematic::Created(GameObject *obj){

    const char **cinematic_name;
    int x;
    int i;

    x = Get_Int_Parameter("Number_Of_Cinematics");

    for (i = 0; i < x; i++) {
        cinematic_name[i] = Get_Parameter("Cinematic_name");
    }

    char cinematic_array[x][10000000]; // bad, do something about the 1000000000000000 :P

    for(i = 0; i < x; i++){
        cinematic_array[i] = cinematic_name[i];
    }

does that fix the problem? (something looks fishy with declaring cinematic_array, I dunno, fix it if you can, or maybe it's alright)

I might have mixed
  • and [10000000] around, forgot a bit about 2D arrays, but it should work
Logged

Reborn

  • Donator
  • Offline Offline
  • Posts: 200
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #8 on: February 13, 2008, 09:49:08 AM »

The problem lies here:

Code: [Select]
    for (i = 0; i < x; i++) {
cinematic_name[i] = Get_Parameter("Cinematic_name");
}

You see the "Cinematic_name" would have to be a unique string as this is what the user see's in level edit. But I think you get what I mean now.

All that code has done is compounded the problem. All your loop is actually doing is making all the elements of the cinematic_name array set to Get_Parameter("Cinematic_name");, which is exactly what was happening before, only directly instead of indirectly.

What I really need is to create an array for the string name that "Get_Parameter" uses.
Something like the loops we've been exploring but only for this:

Code: [Select]
cinematic_name[i] = Get_Parameter("Cinematic_name[i]");
The only thing is that whatever is between the ""'s is counted as a character. I now there are some special cases like \n that do not count, but I have no idea if what I am suggesting is actually possible.

Thanks for your help though, i'm prettty sure we're now on the same page :-)
« Last Edit: February 13, 2008, 10:09:49 AM by Reborn »
Logged

Whitedragon

  • Network Administrator
  • Offline Offline
  • Posts: 1163
    • View Profile
    • http://black-cell.net
Re: Dynamic array sizes and the renegade API
« Reply #9 on: February 13, 2008, 10:44:41 AM »

Script parameters can't be dynamically generated that way. What you could do is make one parameter for all the cinematics and then separate them with ;, so it would look like "cinematic1.txt;cinematic2.txt;cinematic3.txt." You would then randomly choose one similarly to the random building selection code.
Logged
DragonServ, Renegade's first IRC interface bot
Creator and lead coder (2002 - )

Dragonade, Renegade's first server side modification
Lead coder (2005 - )

DragonGuard, Renegade's first server side anti-cheat
Creator and lead coder (2006 - 2008)

SSAOW/SSGM, Renegade's most used piece of software
Lead coder (2005 - 2008)

Reborn

  • Donator
  • Offline Offline
  • Posts: 200
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #10 on: February 13, 2008, 11:01:02 AM »

Thankyou, that's exactly what I needed to know. :-)
Logged

deathdish

  • Offline Offline
  • Posts: 925
    • View Profile
Re: Dynamic array sizes and the renegade API
« Reply #11 on: February 14, 2008, 10:28:42 PM »

eh k I wouldn't have been able to help eventualls :S i have no idea what wd just said lol

EDIT* is this C++? Cos I don't know much of that, and I don't really know what Get_Parameter does heh was just guessing at things :P
Logged
Pages: [1]   Go Up