1 registered members (Ayumi),
1,170
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: SED; help with arrays
[Re: xxGOTARxx]
#255981
03/13/09 22:57
03/13/09 22:57
|
Joined: Mar 2009
Posts: 16
xxGOTARxx
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 16
|
This is what I came up with but it is still not working the way I expected, anyone have any ideas?
#include <acknex.h> #include <default.c>
STRING* one = "0"; STRING* two = "1"; STRING* three = "2";
function msgbox(STRING* new) {
STRING* clearText = " "; STRING* holder_one = " "; STRING* holder_two = " "; STRING* holder_three = " "; str_cpy(holder_one,one); str_cpy(holder_two,two); //str_cpy(holder_three,three); str_cpy(one,clearText); str_cpy(two,clearText); str_cpy(three,clearText);
TEXT* lnONE = { pos_y = 100; string (one); flags = VISIBLE; } TEXT* lnTWO = { pos_y = 110; string (two); flags = VISIBLE; } TEXT* lnTHREE = { pos_y = 120; string (three); flags = VISIBLE; } str_cpy(one,new); str_cpy(two,holder_one); str_cpy(three,holder_two);
}
function main() { msgbox("100"); wait(1000); msgbox("is this working"); wait(1000); msgbox("i guess so"); return; }
|
|
|
Re: SED; help with arrays
[Re: xxGOTARxx]
#255984
03/13/09 23:10
03/13/09 23:10
|
Joined: Apr 2006
Posts: 737 Ottawa, Canada
Ottawa
User
|
User
Joined: Apr 2006
Posts: 737
Ottawa, Canada
|
Hi! Is : STRING* clearText = " "; inside a function? Try it outside the function...it will become global and not local. Ottawa ![smile smile](/ubb7/images/graemlins/default_dark/smile.gif)
Last edited by Ottawa; 03/13/09 23:11.
|
|
|
Re: SED; help with arrays
[Re: xxGOTARxx]
#256000
03/14/09 02:02
03/14/09 02:02
|
Joined: Dec 2006
Posts: 434 UK,Terra, SolarSystem, Milky W...
pararealist
Senior Member
|
Senior Member
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
|
Hi, I found this and saved it when i was browsing the forum. Havent used it yet but thought it could be usefull.
//ARRAY of STRINGS
STRING** tst;
tst = malloc((long) sizeof(STRING*) * number of elements);
//tst = malloc((int) sizeof(STRING*) * number of elements);
for(int i=0;i<number of elements;i++)
tst[i]=str_create("#number of characters");
//now you can access the string array like this:
str_cpy(tst[0],"hallo");
hope this is what you need?
A8.3x Commercial, AcknexWrapper and VS 2010 Express ○pararealist now.
|
|
|
Re: SED; help with arrays
[Re: pararealist]
#256002
03/14/09 02:15
03/14/09 02:15
|
Joined: Mar 2009
Posts: 16
xxGOTARxx
OP
Newbie
|
OP
Newbie
Joined: Mar 2009
Posts: 16
|
I found that post also I could not get it to work, I am going to play around with it some more. **now where did my old c programming book end up at** ![smirk smirk](/ubb7/images/graemlins/default_dark/smirk.gif) UPDATE! I got it to work by changing that code a bit i used... STRING** tst; tst = malloc((long) sizeof(STRING*) * 10); var i = 0; // declared a var for(i=0;i<10;i++) // removed the int tst[i]=str_create("#10"); next... How would I use that with TEXT* box = { layer = 15; string(tst); flags = VISIBLE; } did not work...
Last edited by xxGOTARxx; 03/14/09 02:32.
|
|
|
Re: SED; help with arrays
[Re: xxGOTARxx]
#256293
03/15/09 21:49
03/15/09 21:49
|
Joined: Dec 2006
Posts: 434 UK,Terra, SolarSystem, Milky W...
pararealist
Senior Member
|
Senior Member
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
|
So,
STRING* sTextString1 = "Welcome\n"; STRING* sTextString2 = "This is"; STRING* sTextString3 = " a "; STRING* sTextString4 = "Text"; STRING* sTextString5 = "\nand this another line!";
TEXT* tInfo = { layer = 25; pos_x = 300; pos_y = 300; string (sTextString1, sTextString2, sTextString3, sTextString4, sTextString5); // create an array of 5 string pointers flags = SHOW; }
Now you can access the strings with tInfo.pstring[0] // (0-4) e.g
str_cpy(tInfo.pstring[0],"your text");
Time we got proper arrays me thinks.
Last edited by pararealist; 03/15/09 21:50.
A8.3x Commercial, AcknexWrapper and VS 2010 Express ○pararealist now.
|
|
|
Re: SED; help with arrays
[Re: pararealist]
#256636
03/17/09 21:20
03/17/09 21:20
|
Joined: Mar 2009
Posts: 112 Germany
KDuke
Member
|
Member
Joined: Mar 2009
Posts: 112
Germany
|
Though if you want to have several text-objects you have to do it this way
#include <acknex.h>
#include <default.c>
TEXT** myTextArray;
function main()
{
int numberOfNeededTextObjects;
myTextArray = (TEXT**)malloc((int)sizeof(TEXT*)*numberOfNeededTextObjects);
//Now you can acces the text objects in following manner
(myTextArray.layer)[0] = 25;
(myTextArray.pos_x)[0] = 100;
and so on...
}
EDIT: Oh yeah I forgot to mention. You should make an exit-function which frees the memory again if you use malloc. Like
#include <acknex.h>
#include <default.c>
on_esc = myExitFunction;
function myExitFunction()
{
free(myTextArray);
} greetings KDuke
Last edited by KDuke; 03/17/09 21:23.
Using A7 Free Click and join the 3dgs irc community! Room: #3dgs
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|