|
Create Blocks during runtime ||| Zur Laufzeit erstellte Entities
#230458
10/05/08 16:35
10/05/08 16:35
|
Joined: Oct 2008
Posts: 24 Germany
Hazardos
OP
Newbie
|
OP
Newbie
Joined: Oct 2008
Posts: 24
Germany
|
[Scroll down for something English-like]
Hallo liebe Leute,
in sämtlichen Tutorials und im Handbuch zu GS konnte ich zu meiner Frage bislang keine Antwort finden. Ich habe folgendes Problem an dem ich zurzeit knusper:
Ausgangssituation: In einer separaten Datei habe ich ein Level geschrieben. Es ist eine Aneinanderreihung von Blöcken mit entsprechenden Eigenschaften, wie Position, Skalierung und Farbe.
Zuvor die Frage: Wie kann man einen einzelnen Block zur Laufzeit erstellen? (ohne model oder map etc.!!!!!!)
Ich helfe mir mit einem "Einheitsblock" als mdl aus, welchen ich entsprechend skaliere und das material entsprechend der Datei einstelle. Nun das Problem: Das Material ist bei allen Blöcken gleich!
abstrahierter Code wie folgt:
- Eigenschaften aus Datei auslesen - Entity mit entsprechender Position erzeugen und dem Pointer my zuweisen - Entity skalieren - über my.material... die Materialeigenschaften zuweisen
und das ganze so oft hintereinander wie laut Datei Blöcke benötigt werden.
Warum funktioniert die Positionszuweisung und Skalierung tadellos, nur die materialzuweisung nicht? Wahrscheinlich ein dummer Anfängerfehler o_O
MfG Jörn ------------------------------- Zuletzt eine kleine Frage nebenbei: Wie kann ich lite-c sagen, dass ich keine Map brauche? (Map wird via Code erstellt)
_____________________________________________________
Hello folks,
I've got one question for you:
I want to create blocks during runtime, therefore I have got a file which contains position, size and color of each block. I read this file during runtime and create blocks. I can position and scale them as defined in the file, but the material is the same.
the code does something like: -read file, get position/size/color - create an Entity which contains only one block and set the pointer my to the new created Entity - set Position and scaling - now i set the material-settings with my.material...
the blocks are created right, but they look all the same! Why??
A little question before the end: -How can I tell lite-c, that I don't want to use a map or terrain and still run the engine? - I've helped myself out by using a model which contains a block. But how can I create blocks just with the engine, without extern files?
Whoever may find faults can keep them :-P
Greetings, Jörn
|
|
|
Re: Create Blocks during runtime ||| Zur Laufzeit erstellte Entities
[Re: Stromausfall]
#230490
10/05/08 23:10
10/05/08 23:10
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Try adding a dummy action to the created entities that will run long enough for you to finish changing its prioerties. eg. action ent_dummy() { wait(10); }
Otherwise, please post the code chunk that reads the file and creates the blocks, and I'll have a look.
I think the 'little' answer you're looking for is level_load(NULL);
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Create Blocks during runtime ||| Zur Laufzeit erstellte Entities
[Re: EvilSOB]
#230500
10/06/08 07:00
10/06/08 07:00
|
Joined: Jul 2007
Posts: 959 nl
flits
User
|
User
Joined: Jul 2007
Posts: 959
nl
|
Because if you change the properties of a model - all entities which use this model, are also changed. Because all entities which use this model only use this ONE model and not copies of it - as far as i know.
search this up in the manaul
ent_clone(ENTITY*); ent_cloneskin(ENTITY*);
"empty"
|
|
|
Re: Create Blocks during runtime ||| Zur Laufzeit erstellte Entities
[Re: flits]
#230501
10/06/08 08:16
10/06/08 08:16
|
Joined: Oct 2008
Posts: 24 Germany
Hazardos
OP
Newbie
|
OP
Newbie
Joined: Oct 2008
Posts: 24
Germany
|
Die verwendete Datei sieht so aus: The file looks like this: start/Am Anfang: 2 bytes which defines the number of blocks in the Level 2 bytes, welche die Anzahl der Blöcke angeben for each Block/für jeden Block: - X (2 byte) - Y (2 byte) - z (1 byte) - scale_x (1 byte) - scale_y (1 byte) - color R - color G - color B The code still works for different positions. But even by using ent_clone/or ent_cloneskin in the for-command the color of all blocks becomes the color of the last block. Dies ist der Code, welcher die Entitys erzeugt, verschiedene Positionen und Skalierungen zuweist, aber allen das gleiche Material übergibt! ent_clone/ent_cloneskin funktioniert leider nicht.
fhandle = file_open_read("Level01.txt");
Block_Count = file_asc_read(fhandle)*256 + file_asc_read(fhandle);
for (i=1; i<=Block_Count; i++)
{
my = ent_create("Level01\\Block.mdl", vector (
file_asc_read(fhandle) + file_asc_read(fhandle)*256,
file_asc_read(fhandle) + file_asc_read(fhandle)*256,
file_asc_read(fhandle)), NULL);
ent_clone (my);
my.scale_x = file_asc_read(fhandle);
my.scale_y = file_asc_read(fhandle);
my.material.emissive_blue = file_asc_read(fhandle);
my.material.emissive_green = file_asc_read(fhandle);
my.material.emissive_red = file_asc_read(fhandle);
my.material.ambient_blue = 0;
my.material.ambient_green = 0;
my.material.ambient_red = 0;
}
file_close(fhandle);
thanks for your help! dankeschööööön! ;-) Greetings Jörn
|
|
|
Re: Create Blocks during runtime ||| Zur Laufzeit erstellte Entities
[Re: Hazardos]
#230520
10/06/08 13:15
10/06/08 13:15
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
I can see two possible causes for the problem. First - does your "block.mdl" have an actual built-in material? (in MED go to EDIT / MANAGE_SKINS and click SKIN SETTINGS button, and make sure the skin has the MATERIAL_SETUP tickbox ticked ON. If not, put it ON then save and re-run your existing code. )Otherwise try this, fhandle = file_open_read("Level01.txt");
Block_Count = file_asc_read(fhandle)*256 + file_asc_read(fhandle);
for (i=1; i<=Block_Count; i++)
{
my = ent_create("Level01\\Block.mdl", vector (
file_asc_read(fhandle) + file_asc_read(fhandle)*256,
file_asc_read(fhandle) + file_asc_read(fhandle)*256,
file_asc_read(fhandle)), NULL);
//ent_clone (my); // not needed probably
my.scale_x = file_asc_read(fhandle);
my.scale_y = file_asc_read(fhandle);
my.material = mtl_create(); // <<< major change
//my.material.??? = ???; // <<< may need to change some defaults
my.material.emissive_blue = file_asc_read(fhandle);
my.material.emissive_green = file_asc_read(fhandle);
my.material.emissive_red = file_asc_read(fhandle);
vec_set(my.material.ambient_blue, nullvector); //for tidyness sake
}
file_close(fhandle);
Let us know which helps, if any...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Create Blocks during runtime ||| Zur Laufzeit erstellte Entities
[Re: Hazardos]
#230649
10/07/08 13:36
10/07/08 13:36
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hah! I wish I knew. I am looking at having to create terrain blocks on the fly using similar to your code.
Best of luck.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|