Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (Ayumi, NewbieZorro, TipmyPip), 13,888 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: adding information to a non moving character?? [Re: jamesk85] #68449
03/29/06 14:12
03/29/06 14:12
Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
ulillillia Offline
Senior Expert
ulillillia  Offline
Senior Expert

Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
You need to assign the pointer:

Code:

entity* nonmovingentity; // a global entity pointer

// insert this code at the very top of your action before the while loop

nonmovingentity = me; // assigns the pointer to the entity
while (!nonmovingentity)
{
wait(1); // read note for reason for this
}

// other code you have goes here



The reason why you need that extra bit is, if the entity is not present, the pointer becomes invalid and an error will occur. This makes the engine wait until the entity pointer is valid (or is present in the case of using ent_create) and when it is valid (or present), the loop becomes false and the second while loop initiates.

Also, the text cannot be places in an action or inside a function. It needs to be kept outside of a function (and above the action that uses it).

I, too, was one very confused with scripting. Through the use of two side projects (my 2D game is the main one) and reading replies from others to similar issues, I've learned a lot.


"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials
Re: adding information to a non moving character?? [Re: ulillillia] #68450
03/29/06 14:27
03/29/06 14:27
Joined: Mar 2006
Posts: 43
J
jamesk85 Offline OP
Newbie
jamesk85  Offline OP
Newbie
J

Joined: Mar 2006
Posts: 43
ok. I got the first one fixed. the pointer is working now but I'm not sure what you mean about the text problem.
so text cant be in the action. so must I place it in a function and call that function or what do I have to do.

tell me about it. I left it way too late to learn the scripting and now im in big trouble! I love to be able to go through other questions but I really dont have the time.

Re: adding information to a non moving character?? [Re: jamesk85] #68451
03/29/06 15:24
03/29/06 15:24
Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
ulillillia Offline
Senior Expert
ulillillia  Offline
Senior Expert

Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
A text cannot be in an action. A text is like a function in terms of how it is placed:

Code:

var my_var = 2; // a variable declaration
string my_string = <filename.tga>; // file name string declaration
string another_string = "I'm a nice string, ain't I?"; // declares a string with content in quotes

text textobject
{
// definition of text object
}

panel mypanel
{
// panel definitions
}

action my_action
{
while(1)
{
// code for a loop
textobject.string = "I'm now a changed string!"; // semicolon at end of a statement
mypanel.pos_y = 5+(2*my_var); // some screwy simple formula
}
// action code - no text objects, panels, etc. in here, just plain code (and function calls)
}

function my_function (parameter1, parameter2)
{
if (parameter1 == 3)
{
my_var = 5; // set only if the condition is true
}

if ((parameter1 !=3) && ((parameter1 <= 5) || (parameter2 > 6))) // complex statement
{
my_var += parameter1/3;
}
}

function main()
{
// the main function and it's code. I use it to get core components working and running.
my_function(3, 8);
}



This is the structure in a very simple manner to help explain. I'm commenting out notes which leave blank functions with nothing in them. I'm doing this to help explain. This is nothing compared to my 2D game's script which has over 22,000 lines (likely to reach or pass 30,000 by the time it's done)....


"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials
Re: adding information to a non moving character?? [Re: ulillillia] #68452
03/29/06 16:44
03/29/06 16:44
Joined: Mar 2006
Posts: 43
J
jamesk85 Offline OP
Newbie
jamesk85  Offline OP
Newbie
J

Joined: Mar 2006
Posts: 43
text info1
{
pos_x = 4;
pos_y = 10;
layer = 15;
string = "Please let this work!!";
flags = visible;
}


entity* nonmovingentity;

action displayinfo1_player
{
nonmovingentity = me;

while(!nonmovingentity)
{
wait(1);
}

while(1)
{
if(vec_dist(nonmovingentity.x, player.x) > 20)
{
wait(1);
}
else
{
info1.string:
}
}
}

This is what I now have in the code. It runs but a meassage comes up saying
"empty pointer in displayinfo1_player" I click ok twice and it goes away.
do you know whats wrong here.
And just to clarify...is nonmovingentity a predefined name for all characters that dont move?? and is player a predefined name for the avatar of the game??
because in the code above i put "action displayinfo1_player" and i'm not sure if player is supposed to be put there??

Re: adding information to a non moving character?? [Re: jamesk85] #68453
03/29/06 17:19
03/29/06 17:19
Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
ulillillia Offline
Senior Expert
ulillillia  Offline
Senior Expert

Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
Nonmovingentity is doubtfully a predefined name. I don't know about player, but it seems quite common. As to your error, the most likely cause I can come up with is that the player pointer has not been defined yet. Instead of player.x, you could use camera.x instead. This uses the camera instead of a player. If you do have a player (I don't), then you need another pointer. Pointers are formatted like this in C-script:

entity* player; // the * is a pointer with the name following. It can later be assigned by script.

Also, you have "info1.string" done incorrectly. You're very close though:

info1.string = "Your new string content goes here";

You have to manually add hard returns (although you could write a script to do it, I do it manually with my hypercount ability for short range and rare use, but a string of digits on top commented out to help as well which is even faster than my hypercount ability is. I have the format as:

123456789A123456789B123456789C12

For 32 characters. I then just move it along starting immediately after the \n.

Ya know, I think you should read and go through the scripting tutorials. Posting here isn't bad either. I may seem to be gone, but I'm working on my 2D game's clouds while waiting for anything new. I'll be around until about noon to 12:30 PM Central Time when I end up going to bed.


"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials
Re: adding information to a non moving character?? [Re: ulillillia] #68454
03/29/06 18:40
03/29/06 18:40
Joined: Mar 2006
Posts: 43
J
jamesk85 Offline OP
Newbie
jamesk85  Offline OP
Newbie
J

Joined: Mar 2006
Posts: 43
ok thanks. I'll give another look at the tutorial but to be honest I dont think its very good and I really only have a few days left to get this done so I'm in panic mode. Thanks so much for the time your giving though, its really sound of you.
I'll see what I come up with anyway.

Re: adding information to a non moving character?? [Re: jamesk85] #68455
03/29/06 21:46
03/29/06 21:46
Joined: Mar 2006
Posts: 43
J
jamesk85 Offline OP
Newbie
jamesk85  Offline OP
Newbie
J

Joined: Mar 2006
Posts: 43
Ok....well ben working pretty hard at it and looked up a lot and got it to work. only thing is...when you get near the char the text appears however when u walk away from the char the text still stays and I cant think of a way to get around this problem. any idea??

The code is like this:
text info1
{
pos_x = 4;
pos_y = 10;
layer = 15;
string = "";
flags = visible;
}

entity* Max2_MDL_001;


action displayinfo1
{
Max2_MDL_001 = me;

var i=1;

while(i)
{
if(vec_dist(me.x, plBiped01_entity.x) > 150)
{

wait(1);

}
else
{

info1.string = "this text appears when u get near the char";


i=0;

}
//i=1;
}

}

Re: adding information to a non moving character?? [Re: jamesk85] #68456
03/30/06 11:22
03/30/06 11:22
Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
ulillillia Offline
Senior Expert
ulillillia  Offline
Senior Expert

Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
As a side note, you don't need a var equal to 1 to make a while loop, just "while(1)" is all you need. If a condition is used, then that's a different case.

To make the text disappear, have:

info1.visible = off;

before the wait instruction in the first if statement. To make it reappear, have the same thing copied just after the else part only with "on" instead of "off". Like this:

Code:

text info1
{
pos_x = 4;
pos_y = 10;
layer = 15;
string = "";
flags = visible;
}

entity* Max2_MDL_001;

action displayinfo1
{
Max2_MDL_001 = me;

var i=1;

while(i)
{
if(vec_dist(me.x, plBiped01_entity.x) > 150)
{
info1.visible = off; // too far, text is invisible
wait(1);
}

else
{
info1.visible = on;
info1.string = "this text appears when u get near the char";
i=0;
wait(1);
}
}

//i=1;
}
}



I provided the tabbing so you can better see the structure.

Color-coded notes:

Red - hazardous - often causes compiler errors
Orange - caution - avoid doing these
Yellow - a note - otherwise harmless
Green - a fix I made

Red - Going down the list, in the text object declaration, you do not need to declare a string right away. Although this won't do anything, it is not essential and you can go without.
Orange - To get a while loop to work, having this is not neccessary. Although it won't do much damage, it can cause a slowdown (extremely slight) and use up 4 bytes of memory (extremely miniscule).
Green - This makes the text object invisible. If the distance is greater than 150 quants, the text will not be visible.
Green - This makes the text object visible. If the above condition is not true (within 150 quants), the text will become visible.
Orange - Having this, given your while loop, it could become false. Unless you want to terminate the loop, you do not need this.
Green - If the else condition is always used the while loop will run indefinitely long and cause the engine to terminate showing an error of a possible endless loop. This fixes this bug. Not all while loops use the wait(1); instruction, most commonly in those that can become false.
Orange - Although commented out, because this is outside the while loop, it won't have any effect at all. All instructions within a while loop are repeated.
Red - You have an extra brace which will likely cause compiler errors or strange, unexpected effects if this code is added on to. It's best to get rid of it.

Hopefully this'll explain a few things that need to be pointed out.


"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials
Re: adding information to a non moving character?? [Re: ulillillia] #68457
03/30/06 12:37
03/30/06 12:37
Joined: Mar 2006
Posts: 43
J
jamesk85 Offline OP
Newbie
jamesk85  Offline OP
Newbie
J

Joined: Mar 2006
Posts: 43
Thats brilliant. Thanks a million!!

Re: adding information to a non moving character?? [Re: jamesk85] #68458
03/30/06 12:40
03/30/06 12:40
Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
ulillillia Offline
Senior Expert
ulillillia  Offline
Senior Expert

Joined: Feb 2003
Posts: 6,818
Minot, North Dakota, USA
Oh, and on this line:

if(vec_dist(me.x, plBiped01_entity.x) > 150)

you need to change the "plBiped01_entity.x" part to "Max2_MDL_001.x" instead, the name of your pointer to the entity.


"You level up the fastest and easiest if you do things at your own level and no higher or lower" - useful tip My 2D game - release on Jun 13th; My tutorials
Page 2 of 2 1 2

Moderated by  HeelX, rvL_eXile 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1