Jump to content

Checking variables


Thralni
 Share

Recommended Posts

I'd like to know if there is a quick and easy way to determine what the highest variable is in a set group of variables. For example: there is variable a, b, c and d. I want to know what the highest one is. Is there a quicker way to do this then the following:

 

Code:
if (a >  {       if (a > c) {               if (a > d) {                       set_flag(x,y,a)}}}// and then do this operation for every other variable

 

Not only is this a lot of work to type out, I fear it may unncesarily slow down the game. Do any of you have a better option available?

Link to comment
Share on other sites

Since we can't write functions in Avernumscript, I think the best way is probably to use an intermediate variable:

 

Code:
int a,b,c,d; //the variables we want to find the max ofint e;...e = a;if(b > e)	e = b;if(c > e)	e = c;if(d > e)	e = d;set_flag(x,y,e);

 

It's not really great, but I can't think of anything much better. Note that if you don't mind potentially losing the value in one of the variables you're choosing among, say a, you could use that one instead of the extra one. If you chose a, you could eliminate the assignment and first conditional in the above code, and change all other occurrences of e to a.

Link to comment
Share on other sites

I made a tiny mistake I'm afraid. It's not the highest, rather the lowest variable what I'm looking for. So anyway:

 

I need to know which variable is lowest, not just the value. In town, there are four points. I need to know to which point the party is closest to, so I can spawn a monster at that point. So what I did, is store the distance from the party to each point in a variable, and now I need to know which variable has the lowest value, so I can determine to what point the party is closest.

Link to comment
Share on other sites

(Would have been posted earlier. Server was slow. At least now I can update my code.)

 

How important is it that you use variables? What AvernumScript really needs is arrays, but you could be able to hack it out with SDFs.

Code:
// i is an integer/short// min_index is an integer/shortmin_index = 0;i = 1;while (i < ARRAY_LENGTH) {    if (get_flag(ARRAY_LOCATION, i) > get_flag(ARRAY_LOCATION, min_index)) {        min_index = i;    }        i = i + 1;}// The SDF with the minimum value will be located at (ARRAY_LOCATION, min_index

 

It would be easier if AvernumScript actually had arrays. Or functions. Or macros. Or for loops. Or pre/post incrementing. Or-

Link to comment
Share on other sites

Ah, I misunderstood. If that's what you need, there's no point in storing all the distances at all:

 

Code:
int i,index,dist,best_dist;//assume that four locations are stored with//their x and y coordinates for location i in flags//(ARRAY_LOCATION,i) and (ARRAY_LOCATION+1,i)//for i=0,...,3//these could be set by the START_SCEN_STATEi=0;best_dist=5000;while(i<4){	dist = distance from party to the point (get_flag(ARRAY_LOCATION,i),get_flag(ARRAY_LOCATION+1,i)	if(dist<best_dist){		best_dist=dist;		index=i;	}	i++;}//point to spwan monster is now://(get_flag(ARRAY_LOCATION,index),get_flag(ARRAY_LOCATION+1,index)

Similar to Dintiridan's suggestion, but you might as well just store the coordinates since they have to be stored in some form anyway. This is about how most of Blades of Rogue works.

Link to comment
Share on other sites

My impression is that Avernum script has been simplified way too much. This is only one example, people frequently need to employ circumlocution. All too often something can't be done or it can be done only with a whole lot of convolution. It is not a very satisfactory compromise between C programming and the Blades of Exile way of doing things.

Link to comment
Share on other sites

Oops, I forgot to fully translate everything from C to Avernumscript.

 

 

Code:
int i,index,dist,best_dist;//assume that four locations are stored with//the x and y coordinates for location i in flags//(ARRAY_LOCATION,i) and (ARRAY_LOCATION+1,i)//for i in the range 0,1,2,3//these could be set by the START_SCEN_STATE//i will be our loop counter, as usuali=0;//best_dist is the best distance we've found so far. We start out by setting it to an //impossibly high value to that the first real value we find will replace it. best_dist=5000;//loop over all of the possible spawn points:while(i<4){	//compute the distance from the spawn point currently being considered to the party	//note that the next line is only pseudo code, must be replaced with whatever method 	//you use to compute the distance	dist = distance from party to the point (get_flag(ARRAY_LOCATION,i),get_flag(ARRAY_LOCATION+1,i)	//if the newly found distance is smaller than the best known distance, we 	//will have found a better spawn point than the previously known best	if(dist<best_dist){		//if we have found a new best point, record it's distance as the best distance		best_dist=dist;		//and its index for later use		index=i;	}	i = i + 1;}//point to spawn the monster is now://(get_flag(ARRAY_LOCATION,index),get_flag(ARRAY_LOCATION+1,index))//can now do:place_monster(get_flag(ARRAY_LOCATION,index),get_flag(ARRAY_LOCATION+1,index),MONSTER_TYPE,NOT_WORTH_XP);

 

I hope that's a bit more clear now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...