argument in function

Posted By: ayks

argument in function - 09/22/11 18:26

hi,

here is my code :

Quote:
function mfj(a)
{
   if (a==0)
   {
      ja1+=a;ja2+=a;ja3+=a;ja4+=a;ja5+=a;ja6+=a;ja7+=a;ja8+=a;ja9+=a;ja10+=a;
   }
}

it would be nice if i could write it easier..
i know use simple argument, but its a little more complicated here.

for automate the jaX+=a list, i could do smt like

Quote:
i=0;
while (i<=10)
{
   ja(i)+=a;i++;

but it can't work this way.. right ?
does anyone have a solution for do this thing ? (like the second quote but working)

thanks
Posted By: WretchedSid

Re: argument in function - 09/22/11 18:50

Reconsider if you really don't want to use an array in this case.
Posted By: Kartoffel

Re: argument in function - 09/22/11 19:04

you can do it like this

Code:
var ja[10];
...
i=0;
while (i<10) // another thing: This has to be i<10 not i<=10
{
   ja[i] +=a;
   i++;
}



you could also do it with for(){} ...but this should work, too

but in your first code:
if(a == 0) [...] ja1 += a; [...] - does this really make sense?!

and be a bit careful...
the first var in this array is ja[0] - not ja[1]
Posted By: ayks

Re: argument in function - 09/22/11 22:14

Oh, i see.. the array was the solution.
I'm so dumb.. i use array for all my "gauge" like "chronograph" but I didnt use them for this case..

First I thought it couldnt work because i needed to do the same thing with
ja1.visible=on;ja2.visible=on;ja3.visible=on;ja10.visible=on; and I think its not that simple in this case, but this is another problem.
I hope i will find a solution with that way.

edit : looks unaccessible with strings instead of variables smirk

Anyway, i'll try it right now and i guess there will be no problem.
Thanks for your 2 answers and for the detailed code and the tip.
Posted By: ayks

Re: argument in function - 09/25/11 02:25

Excuse to ask again for help, but i need to do the same thing, instead of

Quote:
ja1+=a;ja2+=a;ja3+=a;


its

Quote:
ja1.visible=on;ja2.visible=on;ja3.visible=on;


Its more complicated since its not only variable.. and all the "ja" are panels.. I can't make an array of panels.
Can anyone tell me the method i have to look for ?

thanks
Posted By: WretchedSid

Re: argument in function - 09/25/11 08:33

You sure can create an array of panels like you can with every data type. What makes you think that its not possible?
Posted By: ayks

Re: argument in function - 09/25/11 11:02

I thought it was more complicated than "simple" variable since it has pos_x, pos_y, layer, bmap and flags.
But if you say so, I have to utilize this way.
I see a last difficulty but I'll try to advance with it for now.
Thanks for your answer
Posted By: ayks

Re: argument in function - 09/25/11 21:31

Hi again,
I advanced a bit, now i have this :

Quote:
TEXT string_array = // create an array of string with a text
{
strings = 20;
string = ("j1","j2", "j3", "j4");
layer=15;
flags = VISIBLE;
}
which is an array of string.
now i need it to work :

Quote:
string_array.string[0].visible=off;

but it don't.

2 questions :
- Is this the good way for doing an array of string ?
- If yes, can i have a tip for make the last quote work ?

thanks
Posted By: PadMalcom

Re: argument in function - 09/25/11 22:28

Okay:
1: You create a text with 20 strings an you initialize only the first 4. Thats bad.
2: You can make a TEXT object visible or not, but not each single string in it. To do so you need an array of TEXT and not only one TEXT object.
Posted By: Superku

Re: argument in function - 09/25/11 23:02

Quote:
2: You can make a TEXT object visible or not, but not each single string in it.

That's not correct, there's a function esp. for this purpose:
txt_set(in)visible(TEXT* text,var index number of string starting at 0);
Posted By: PadMalcom

Re: argument in function - 09/25/11 23:18

Wow thats new to me!
Posted By: ayks

Re: argument in function - 09/25/11 23:49

padmalcom => thanks for the advice
superku => thanks for the advice/correction, I will try to advance with it but it looks complicated.

Maybe I will finish by simply put all the j1.visible=off;j2.visible=off;j3.visible=off; [...] j50.visible=off; If I don't succeed i think it will be a lot more accessible.
Posted By: MrGuest

Re: argument in function - 09/25/11 23:56

have you had a look at draw_text()?
Posted By: ayks

Re: argument in function - 09/26/11 00:00

Just looked at it in the manual,
but I don't need to just draw a text. Thanks anyway, maybe I will need it some day.
By the way, i found a "concrete" example of the function of superku and its more explicite in practice.

edit : just wait.. is the function of superku just for render a text visible or not ? omg I'm lost for now maybe i'll take a break.

re-edit : I was trying to pass by a string in order to put the name of a panel and render it visible or not by adding .visible=off;
I take a break.
© 2024 lite-C Forums