Forum

Help wanted in CSQC with linked lists

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Help wanted in CSQC with linked lists

Postby metalbeast » Fri Aug 20, 2010 12:16 pm

Hi!
I'm trying to make a structured gui. I have a problem with linked lists in CSQC. In SSQC it works, and I don't know what's the problem with it. Root object is working, .first_child is working too, but in other solutions it places the child only to the first place.
What can be wrong?


Source:
void(entity tparent, vector tposition, vector tsize, string ttext, string thint, float ttype, float tflags) createGuiObj = {

entity newGuiObj;
local float i;

newGuiObj = spawn();
setGuiObjAttribs(newGuiObj, tparent, tposition, tsize, ttext, thint, ttype, tflags);

//This will be a root object, like a window
if (tparent == world) {
return;
} else
//If the tparent does not have a child, spawns one as first_child
if (newGuiObj.parent.first_child == world) {
newGuiObj.parent.first_child = newGuiObj;
print("GUIOBJ added with text ",ttext, " to the FIRST CHILD PLACE\n");
return;
}
i = 0;
newGuiObj.parent.current_child = newGuiObj.parent.first_child.next_child; //sets to the firs child
while (newGuiObj.parent.current_child != world) { //find the last child
newGuiObj.parent.current_child = newGuiObj.parent.current_child.next_child;
i++;
}
newGuiObj.parent.current_child = newGuiObj;
print("GUIOBJ added with text ",ttext, " to no ",ftos(i)," child\n");
}
metalbeast
 
Posts: 4
Joined: Tue Jul 06, 2010 7:27 am

Postby Spike » Fri Aug 20, 2010 12:46 pm

newGuiObj.parent.current_child = newGuiObj.parent.first_child.next_child; //sets to the firs child


wut?

isn't that:

newGuiObj.parent.current_child = newGuiObj.parent.first_child.next_child; //sets to the second child

?

you also don't seem to set next_child anywhere in that code.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby metalbeast » Sun Aug 22, 2010 5:40 am

Thanks Spike, now I can use it, but a bit different. Now, current child is the last child spawned.

entity (entity tparent,string ttext) createGuiObj = {

entity newGuiObj;
local float i;

newGuiObj = spawn();
newGuiObj.parent = tparent;
newGuiObj.text = ttext;

if (tparent.first_child == world) {
tparent.first_child = newGuiObj;
tparent.current_child = tparent.first_child;
print("GUIOBJ added with text ",ttext, " to no 1 child\n");
} else {
i = 0;
tparent.current_child.next_child = newGuiObj;
tparent.current_child = tparent.current_child.next_child;

print("GUIOBJ added with text ",ttext, " to no ",ftos(countChilds(tparent))," child\n");
}
return tparent.current_child;
}
metalbeast
 
Posts: 4
Joined: Tue Jul 06, 2010 7:27 am


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest