Workshop 11:
Pointer
A pointer is used to store the reference of an object. You want to use the Acknex engine to create a pong clone:
You want players to control the bezel on the left and computers to control the right. The problem is ......In your codeHow can we explain who is a player and who is a computer? The answer is simple: you create a pointer, which is just another name of an object. A typical pointer definition is as follows:
Entity*The_player;
Or
Function*Check_status;
Or
String*My_name;
Or
Panel*Game_over;
Or
Bmap*Health_picture;
OK. It looks like we can define pointers for entities, functions, strings, panels, and bitmap. We simply add "*" before the object keyword.
I know you are feeling dizzy. Let's look at an example: Start Wed to open the work11 level file:
This level is a slightly revised version of the previous house and wizards model:
This time we have two wizards to run it:
OH, I see it! The two wizards wear blue and red! They do nothing but do not go through any animation frames, just like the first tutorial, because the wizard has an action attached to it. Adding any action will stop the chaotic animation.
To write some console code. press Tab and enter the following code:
Wizard. x = 300;
The red wizards are close to the camera.
But why did the red wizards move? Why is blue not moved? Why are they not moving at the same time?
I'm afraid I can't handle so many questions, but I will give you a phrase to answer all these questions: I used a pointer for the red wizards. You see, we live in a cruel world. These vicious computers don't care about us. We know what a wizard model looks like, but computers are not interested. If you tell your computer to move the red wizards, it will laugh at you, and it does not know or care who is a wizard. You can only use one pointer to direct objects that require special treatment.
To start Sed and open the script11 file:
Thank God! The script does not look very complicated!
We set the screen and color depth, define a string named work11_wmb (the level to be loaded), and define a pointer named "wizard ". Let's look at the Code:
Entity*Wizard;
The Main function simply loads the work11_wmb of the level. Let's take a look at the action wizard_with_pointer:
Action wizard_with_pointer
{
Wizard = me;
My. ambient = 100;
}
The first row allocates pointers to an object. "Wizard = me;" means I'm a wizard! I have attached the action entity and will know "wizard" from now on ". The wizard_with_pointer action has been attached with a red wizards model, so the red wizards become "wizard ".
Set ambient to 100 in the second row to make it look brighter. Want to know what is different? See the following:
The second row has no pointer, so all it does is increase the ambient value.
Action wizard_simple
{
My. ambient = 100;
}
This is the action attached to the Blue model. I forgot to tell you that "my" is also a pointer! It is previously defined and therefore does not need to be defined. Don't worry, we will talk about it at the end.
OK. How do I create a pointer? There are two steps:
1) define the pointer:
Entity*Horse;
2) Let's tell the pointer who is its owner and put a line of code in the action:
Action players_horse
{
Horse = me;
............
}
Now you can control the object to use the dot method:Object. property.
Start the game and enter the following code to the console:
Wizard. z = 100;
The wizard has indeed changed its height! You can play x, y, z, pan, tilt, roll ...... If you want to hide wizards:
Wizard. invisible = on;
It will disappear! Input:
Wizard. invisible = off;
You can see it again.
The good news is that you can change the properties of the red wizards through any function or action in the script. Copy the following code to the end of your script10 file:
Function move_up ()
{
Wizard. z = wizard. z + 5;
}
On_u = move_up;
The modified script file looks like this:
You can see that the move_up function increases the height (z) by 5. If its initial height is 15, the function is set to 20. The following line of code looks strange:
On_u = move_up;
On_u indicates "when the player presses the U key" and move_up is a function name,No parenthesesEvery time we press the U key, it will be executed (it does not affect the Caps Lock ON or OFF ). As the end, every time we press the U key, the move_up function will increase the height of the red wizards by 5.
Save the script, start the level, and press the U key several times to move the Red Wizard. Obviously, the move_up () function knows who is a "Wizard ".
Note: The most important pointer for Acknex is "my ". Take a look at the action function:
Action wizard_simple
{
My. ambient = 100;
}
The ambient of the attached object is set to 100 in the code. Think of it as a universal pointer. Every entity can use it, but it does not know anything other than an action or function. If you enter:
My. invisible = on;
It does not work on the console, because "my" does not know what it is. However, the following code will render the object invisible because the action is attached with the object:
Action hide_me
{
My. invisible = on;
}