Simplification?

Posted By: PlaystationThree

Simplification? - 01/09/09 05:18

Is there a way simplify this? Thanks in advance smile

Code:
  ...
   str_cpy((text1.pstring)[0],"value1");
   str_cpy((text2.pstring)[0],"value2");
   str_cpy((text3.pstring)[0],"value3");
   str_cpy((text4.pstring)[0],"value4");
   str_cpy((text5.pstring)[0],"value5");
   str_cpy((text6.pstring)[0],"value6");
   str_cpy((text7.pstring)[0],"value7");
   str_cpy((text8.pstring)[0],"value8");
   str_cpy((text9.pstring)[0],"value9");
   str_cpy((text10.pstring)[0],"value10");
    ...
 


This actually goes on up to 100 TEXT* structs, which is the reason for simplification.
Posted By: Quad

Re: Simplification? - 01/09/09 05:20

you may try using a text array? and you may try texts with more than 1 lines?
Posted By: PlaystationThree

Re: Simplification? - 01/09/09 05:56

A text array? Could you elaborate, I've not heard of it before. The text with multiple lines is a good idea though. Thanks you very much.
Posted By: Quad

Re: Simplification? - 01/09/09 08:17

TEXT array:

Code:
TEXT* txt_array[40];


int main(){
	
	
	int i =0;
	for(i=0;i<40;i++){
		txt_array[i]=txt_create(1,1);
		txt_array[i].pos_y = 10*i;
		set(txt_array[i],SHOW);
		str_cpy((txt_array[i].pstring)[0],"initial text");
	}

}


multi-line text ver1:
Code:
TEXT* txt ={
	strings = 40;//40 lines
	flags = SHOW;//  VISIBLE changed as SHOW in 7.66
}

int main(){
	int i =0;
	for(i=0;i<40;i++){
		str_cpy((txt.pstring)[i],"initial text");
	}
}


ver 2:
Code:
TEXT* txt ={
	strings = 1;//1 strings
	flags = SHOW;//  VISIBLE changed as SHOW in 7.66
}

int main(){
	int i =0;
	str_cpy((txt.pstring)[0],"initial text\n");
	for(i=0;i<39;i++){
		str_cat((txt.pstring)[0],"initial text\n");
	}
}

Posted By: testDummy

Re: Simplification? - 01/09/09 13:33

Code:
// not equivalent to above & may be irrelevant
// untested - but similar should work
// temps
var i = 0;
STRING* s1_ = "#128";

// dumps var array into strings of TEXT object
// _t TEXT object
// _na  var array  (i.e. var1[32])
// _nLen length of var array or number of elements to dump (i.e. 32)
void varf_toText(TEXT* _t, var* _na, var _nLen) {
	if (_t == NULL) { return; }
	i = 0;
	for (i = 0; i<_t.strings && i<_nLen; i++);
		str_for_num(s1_, _na[i]);
		str_cpy((text1.pstring)[i], s1_);
	}
}

© 2024 lite-C Forums