https://www.owasp.org/index.php/Testing_for_Race_Conditions_(OWASP-AT-010)
https://github.com/insp3ctre/race-the-web
Where to look
Inspect transfer balance/credit functionalities
Inspect all sensitive operation which can be done simultaneously with 2 users


|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.milk.uberchat.SpeechKinds
This class merely holds string constants for use as the "kind" field of speech messages and methods for mangling kind/text into a nicer human form and for unmangling back to the two separate pieces.
| Field Summary | |
static java.lang.String |
BEEP
|
static java.lang.String |
ECHOES
|
static java.lang.String |
ME
|
static java.lang.String |
MY
|
static java.lang.String |
RAW
speech kind for a raw send to the host system, NL-terminated if appropriate |
static java.lang.String |
RAW_NO_NL
speech kind for a raw send to the host system, no NL-termination |
static java.lang.String |
SAYS
|
static java.lang.String |
SAYS_TO
|
static java.lang.String |
SINGS
|
static java.lang.String |
THINKS
|
| Constructor Summary | |
private |
SpeechKinds()
This class is uninstantiable. |
| Method Summary | |
static java.lang.String |
mangleSpeech(java.lang.String kind,
java.lang.String text)
Take a kind and a message and turn it into a nicer human form, for systems that don't directly support particular kinds. |
static java.lang.String[] |
unmangleSpeech(java.lang.String orig)
Take a human text form and attempt to extract out a kind. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final java.lang.String BEEP
public static final java.lang.String ECHOES
public static final java.lang.String ME
public static final java.lang.String MY
public static final java.lang.String SAYS
public static final java.lang.String SINGS
public static final java.lang.String THINKS
public static final java.lang.String SAYS_TO
public static final java.lang.String RAW
public static final java.lang.String RAW_NO_NL
| Constructor Detail |
private SpeechKinds()
| Method Detail |
public static java.lang.String mangleSpeech(java.lang.String kind, java.lang.String text)
kind
- the kind (should be interned)text
- the message text
public static java.lang.String[] unmangleSpeech(java.lang.String orig)
orig
- the human text form
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |


Episodes
People
Organizations
New Episode
fill up the form to add new episode
episode
date
start time
end time
Venue Details
Organization Name
Organization Address 1
Organization Address 2
Session Details
Title
Session Start Time
Description
Speaker
+ Add another session
Sponsors & Supporters
Sponsors
Supporters
Save
Cancel


Make unhandled promise rejections fail loudly instead of the default silent fail
By default, promises fail silently if you don't attach a .catch()
handler to them.
Use this in top-level things like tests, CLI tools, apps, etc, but not in reusable modules.
Not needed in the browser as unhandled promises are shown in the console.
$ npm install --save loud-rejection
const loudRejection = require('loud-rejection');
const promiseFn = require('promise-fn');
// Install the unhandledRejection listeners
loudRejection();
promiseFn();
Without this module it's more verbose and you might even miss some that will fail silently:
const promiseFn = require('promise-fn');
function error(err) {
console.error(err.stack);
process.exit(1);
}
promiseFn().catch(error);
Alternatively to the above, you may simply require loud-rejection/register
and the unhandledRejection listener will be automagically installed for you.
This is handy for ES2015 imports:
import 'loud-rejection/register';
Type: Function
Default: console.error
Custom logging function to print the rejected promise. Receives the error stack.
MIT © Sindre Sorhus


| C_Histogram::C_Histogram |
( |
int |
numBins, |
|
|
int |
range_min, |
|
|
int |
range_max |
|
) |
| |
|
inline |
Constructor that initializes the class.
- Parameters
-
| numBins | Number of bins per histogram. |
| range_min | Min range of data. |
| range_max | Max range of data. |
| C_Histogram::~C_Histogram |
( |
| ) |
|
|
inline |
Destructor, clears memory (just the pointer, not the object)
| int C_Histogram::Add_Element |
( |
int |
element, |
|
|
int |
id_hist = 0 , |
|
|
char * |
hist_name = NULL |
|
) |
| |
|
inline |
An element is added to the histogram. Returns 0 if the identifier does not fit to the number of histograms. Otherwise, returns 1.
- Parameters
-
| element | New data. |
| id_hist | Histogram identifier inside the histogram vector. If id_hist is bigger than the vector size, a new histogram is created. |
| hist_name | Histogram name. |
| void C_Histogram::Clear_Histogram_Image |
( |
| ) |
|
|
inline |
Erases the histogram image. It is too expensive to keep an image per trixel.
| int C_Histogram::Create_Histograms |
( |
| ) |
|
|
inline |
| void C_Histogram::DrawHistograms |
( |
float |
scaleX = 1 , |
|
|
float |
scaleY = 1 |
|
) |
| |
|
inline |
Draws histograms.
- Parameters
-
| scaleX | Scale on the x axis. |
| scaleY | Scale on the Y axis. |
| void C_Histogram::Equalize_Image |
( |
IplImage * |
src, |
|
|
IplImage * |
dst |
|
) |
| |
|
inline |
| int C_Histogram::Get_Height |
( |
| ) |
|
|
inline |
Returns the graph height.
| vector<CvHistogram *>* C_Histogram::Get_Hist_List |
( |
| ) |
|
|
inline |
| void C_Histogram::Get_Histogram_Image |
( |
IplImage ** |
img | ) |
|
|
inline |
Returns a histogram image.
- Parameters
-
| img | Histogram image pointer. |
| int C_Histogram::Get_NumBins |
( |
| ) |
|
|
inline |
Returns the number of bins.
| int C_Histogram::Get_Offset |
( |
| ) |
|
|
inline |
Returns the offset in order to adjust the text info.
| int C_Histogram::Get_ScaleX |
( |
| ) |
|
|
inline |
| int C_Histogram::Get_ScaleY |
( |
| ) |
|
|
inline |
| int C_Histogram::Get_Width |
( |
| ) |
|
|
inline |
The documentation for this class was generated from the following file:
- /Users/dfreire/Dropbox/_Code/C++/Tritom/Tritom/Tritom_Framework/C_Histogram.h


--- layout: default title: The Team hero-image: url(../assets/images/stock-images/group.jpg) hero-message: Meet the PiE Team hero-button: Join Us! hero-button-url: ../get-involved/join-staff.html ---
{{ advisor.name }}
{{ advisor.title }}
{{ alumnus.title }}


About Us
The CS Society at Ashoka is a rapidly growing space for like-minded people to come together, explore and nurture their interests in Computer Science. The Society has 3 main verticals covering CS Research, Data Structures and Algorithms, Software Development, Machine Learning and much more.
Over the past years, we have conducted multiple interactive workshops, panel discussions, competitions and other events for the CS community on campus and beyond. Among the more notable events, we've partnered with DigitalOcean and CodeChef to conduct various competitions and events throughout the year, conducted Google's ExploreML program on campus and are currently working on Ashoka's first-ever hackathon, RedBrick Hacks. In the past, we've invited guest speakers from our Microsoft Research India, Stanford University and even our own CS faculty.
For the future, we plan on increasing the number of innovative events and taking more steps towards building a healthy community of interdisciplinary computer science enthusiasts.
Our Manifesto
Our Team
Senior Leadership
Advisory
Questions or bug reports?
Head over to our Github repository!


|
||||||||||
| PREV LETTER NEXT LETTER | FRAMES NO FRAMES |
ComponentServiceContextType
object class
AnnotationValidator
interface in order
to validate an annotation is unique appropriate to target element annotated
with Unique
annotation.AnnotationValidator
which is registered in
order to catch exception of annotation validating of given annotation.
Interceptor
.
Interceptor
according to given matcher
Domain
Domain
|
||||||||||
| PREV LETTER NEXT LETTER | FRAMES NO FRAMES |


Core Learnings Outcome
In this blog post I'm going to go through an overview of the Core learnings I have covered in Foundations.
Three new things I have learned about myself and my ego as a result of the core learning
I've learnt about how the brain works in terms of learning, the importance of EQ in comparison with IQ and problem solving. As a result I became more confident about learning programming and coding in general and felt good about my problem solving skills.
What are the role of values, empathy and self awareness in learning and programming?
I believe these 3 elements are the main things that give us direction and drives us. Growing these elements in the right direction would make us a better person. Values, empathy and self awareness are exceptionally important when it comes to programming because of the social aspect of working in a team and the way each team member might approach a problem refers to their level of values, empathy and self awareness.
What has surprised you the most about the core learning?
The emphasis on it in this course which shows that being a programmer is not only coding.
What were the most challenging aspects of the core learning?
For me it was doing the blog posts mostly. The questions sometimes are a bit confusing and kind of vague.
Why do you think we, a programming school, are spending so much time focusing on core learning in a web development bootcamp course?
It looks like there's a shortage of developers with proper soft skills out there which will make developers with this set of skills more likely to land a job in the Tech market.
Does the time you spent studying core learning here feel like a waste of time? Should you have just used that time to practising programming instead? Justify your answer.
I've truely gained by studying the core materials and learnet a lot. Programming is not only codes or the knowledge of coding, if you don't have the right mindset or the right set of skills to comminicate wit your teammates you won't get far as a programmer!


The Friends:Form function allows your users to add/confirm/remove multiple friends within 1 submission. It's an alternate method to using the Friends:Add method. it displays a list of either all current friends, or all site members. Upon form submission, the Friends:Form function will output relevant message(s), and will take care of the rest. Additionally, notifications can be sent out to other members when you request or confirm them as a friend.
{exp:friends:form} content {/exp:friends:form}
Parameters
The following parameters are available for use:
- dynamic
- form_name
- form_id
- group_id
- limit
- member_id
- notification_confirm
- notification_request
- onsubmit
- orderby
- return
- search_screen_name
- search_username
- sort
- subject_confirm
- subject_request
- type
- username
dynamic=
dynamic="off"
This parameter is available to stop the loop from looking into the URI for an ID of any type.
form_name=
form_name="your_form_name"
This parameter allows you to establish a name attribute for the form.
form_id=
form_id="your_form_id"
This parameter allows you to establish an ID attribute for the form.
group_id=
group_id="5|6|9"
This parameter allows you to filter the list of members in the form by one or more group ID's. Separate multiple groups with the pipe (|) character.
limit=
limit="10"
This parameter controls how many results will be outputted. The limit will default to 100 members if a value is not specified.
member_id=
member_id="{segment_3}"
This parameter allows you view a list of friends for a specific member by specifying their member ID. You can hardcode a member ID, pass it through an embed, or grab it from the URI. Alternatively, you can use the username parameter.
notification_confirm=
notification_confirm="friends_notifications/friend_confirm"
This parameter controls which EE template to use for your friend confirm notification template. This is the template that will be used for the message that someone receives when their friend request has been confirmed by the other user.
notification_request=
notification_request="friends_notifications/friend_request"
This parameter controls which EE template to use for your friend request notification template. This is the template that will be used for the message that someone receives when a user has requested to be friends with them.
onsubmit=
onsubmit="some_javascript()"
This parameter allows you to execute Javascript functions at form submission.
orderby=
orderby="screen_name"
This parameter gives you the ability to control the order in which your results are ordered in the list. You can order by any variable that you can parse on as well as random.
return=
return="template_group/template"
This parameter allows you to return the user to a specified template upon successful submittal of form.
search_screen_name=
search_screen_name="ja"
This parameter allows you to filter the member list by those members who share the same first few letters of their screen name. For example, if you specify ja in the parameter, your results may be Jason, Janet, Jared, etc. It's not necessary to specify this parameter though. If you have an additional segment in the URI named screen_name, followed by a value, the search will be performed automatically, as long as the dynamic parameter is NOT set to off.
search_username=
search_username="fur"
This parameter allows you to filter the member list by those members who share the same first few letters of their username. For example, if you specify fur in the parameter, your results may be furly, furby, furnace_eater, etc. It's not necessary to specify this parameter though. If you have an additional segment in the URI named username, followed by a value, the search will be performed automatically, as long as the dynamic parameter is NOT set to off.
sort=
sort="desc"
You can sort by asc or desc.
subject_confirm=
subject_confirm="{friends_inviter_screen_name} has confirmed you as a Friend!"
This parameter outputs the subject line for the notification email when a user is confirming a friend request.
subject_request=
subject_request="{friends_inviter_screen_name} has added you as a Friend!"
This parameter outputs the subject line for the notification email when a user is initiating a friend request.
type=
type="mine"
This parameter allows you to designate which type of member list to retrieve. Indicating mine will display a list of your friends. Indicating member will display a list of all members of the site.
username=
username="{segment_3}"
This parameter allows you view a list of friends for a specific member by specifying their username. You can hardcode a username, pass it through an embed, or grab it from the URI. Alternatively, you can use the member_id parameter.
Variables
All standard and custom member fields and usual Friends variables are available for use here. Additionally, these exist as well:
friends_invitee_member_field
{friends_invitee_member_field}
You can parse standard member fields for both the invitee and inviter for use in the Notification Templates as well as the subject_request and subject_confirm parameters. To parse standard member fields for the invitee, prepend your variables with friends_invitee_. To construct this variable, simply use friends_invitee_ + member_field_name.
friends_inviter_member_field
{friends_inviter_member_field}
You can parse standard member fields for both the invitee and inviter for use in the Notification Templates as well as the subject_request and subject_confirm parameters. To parse standard member fields for the inviter, prepend your variables with friends_inviter_. To construct this variable, simply use friends_inviter_ + member_field_name.
Variable Pairs
The following variable pairs are available for use:
Note: You cannot use both variable pairs together in the same form. They must each be used seperately.
invites
{invites} {/invites}
This variable pair will display all "incoming" friend requests from other users, and is used to establish the formatting of each row of results contained inside your form. This way, you can quickly check off all friend requests you wish to confirm or remove.
members
{members} {/members}
This variable pair is used to establish the formatting of each row of the member list that will be contained inside your form.
Conditionals
You can run conditionals on any of the single variables available above. Additionally, these exist as well:
if friend
{if friend == "y"}{/if}
This conditional determines whether or not a given member in your list has been added to your friends list. It will return either y or n. You would normally use this as a conditional.
Form Fields
The following form fields are available for use:
friends_delete
<input type="checkbox" name="friends_delete" value="yes" />
This field allows your users to remove the selected members from their list of friends when they submit the form. If this checkbox is selected, it will remove any friends the user has selected in the list upon submission. If left unchecked, the members selected in the list will be invited/confirmed.
friends_member_id
<input type="checkbox" name="friends_member_id[]" value="{friends_member_id}" />
This field allows you to create a list of members to either be added or deleted from a friends list. Make sure you specify the name of the field with [ ] so that the Friends module knows that an array of members is being submitted.
Examples
The following example will display a list of all site members, allowing a user to multi add or remove other members from their friends list (and will send email notifications upon successful Friend requests/confirms):

Add or Delete Members to your account using the form below:
 {exp:friends:form type="member" return="friends/form/thanks" notification_request="friends_notifications/friend_request" notification_confirm="friends_notifications/friend_confirm" subject_request="{friends_inviter_screen_name} added you as a friend!" subject_confirm="{friends_inviter_screen_name} confirmed your friend request!" }
 {members}
 <input type="checkbox" name="friends_member_id[]" id="member_{friends_member_id}" value="{friends_member_id}" {if friend == "y"} checked="checked" {/if} /> {if friend == "y"}  {friends_screen_name}  (already added) {if:else}  {friends_screen_name}  {/if}
 {/members}

<input type="checkbox" name="friends_delete" id="friends_delete" value="yes" /> Delete?

<input type="submit" name="submit" value="Submit" />
 {/exp:friends:form}
The following example will display a list of all “incoming” friend requests from other users, allowing a user to multi add or remove the requests from their lists. (and will send email notifications upon successful Friend confirmation):

Friend Requests Awaiting Confirmation:
 {exp:friends:form type="member" return="friends/form/thanks" notification_request="friends_notifications/friend_request" notification_confirm="friends_notifications/friend_confirm" subject_request="{friends_inviter_screen_name} added you as a friend!" subject_confirm="{friends_inviter_screen_name} confirmed your friend request!" }
 {invites}
 <input type="checkbox" name="friends_member_id[]" id="member_{friends_member_id}" value="{friends_member_id}" />  {friends_screen_name}  (requested {friends_entry_date format="%Y-%m-%d"})

<input type="checkbox" name="friends_delete" id="friends_delete" value="yes" /> Delete?

<input type="submit" name="submit" value="Submit" />
 {/exp:friends:form}
Notification Templates
For your notification templates, you use regular EE templates, and just add code like this:
Friend Request ("friends_notifications/friend_request")
Hello {friends_invitee_screen_name}! You have just received a Friend Request from {friends_inviter_screen_name}. Click the link below to accept this invitation: {path='friends/add'}/{friends_inviter_member_id}/
Friend Confirm ("friends_notifications/friend_confirm")
Hello {friends_invitee_screen_name}! You are now friends with {friends_inviter_screen_name} because they have accepted your invitation. Click the link below to view their profile: {path='friends/profile'}/{friends_inviter_member_id}/


The ggf-sepia classes add a sepia effect to an element.
Note: The ggf-sepia classes are not supported in IE 11 and earlier versions.
Normal:
ggf-sepia-min:
ggf-sepia:
ggf-sepia-max:


The synapser
package provides an interface to Synapse, a collaborative workspace for reproducible data intensive research projects, providing support for:
The synapser
package lets you communicate with the Synapse platform to create collaborative data analysis projects and access data using the R programming language. Other Synapse clients exist for Python, Java, and the web browser.
synapser
is available as a ready-built package for Microsoft Windows and Mac OSX. For Linux systems, it is available to install from source. Please also check out our System Dependencies article for instructions on how to install system dependencies on Linux environments.
synapser
can be installed or upgraded using the standard install.packages()
command, adding the Sage Bionetworks R Archive Network (RAN) to the repository list, e.g.:
install.packages("synapser", repos=c("http://ran.synapse.org", "http://cran.fhcrc.org"))
Alternatively, edit your ~/.Rprofile and configure your default repositories:
after which you may run install.packages without specifying the repositories:
install.packages("synapser")
If you have been asked to validate a release candidate, please use:
install.packages("synapser", repos=c("http://staging-ran.synapse.org"))
Under the hood, synapser
uses reticulate
and the synapsePythonClient, which is why you are required to have an installation of Python if you don’t already. See instructions below on installing/upgrading Python below.
To get started, try logging into Synapse. If you don’t already have a Synapse account, register here:
Please visit the synapser
docs site or view our vignettes for using the synapser
package:
browseVignettes(package = "synapser")
Knit RMarkdown files to Synapse wikis
Code for managing data coordinating operations (e.g., development of the CSBC/PS-ON Knowledge Portal and individual Center pages) for Sage-supported communities through Synapse.
Download the Python installer from the Official Website of Python here.
Install the Downloaded Python Installer
check Install Python and Check the “Add python.ext to PATH”, then click on the “Install Now” button.
Verify the Update
python --version
Note
If it still shows the old version, you may restart your system. Or uninstall the old version from the control panel.
Both python 2x and 3x can stay installed in a MAC. Mac comes with python 2x version. To check the default python version in your MAC, open the terminal and type
python --version
python3 --version
If you don’t then go ahead and install it with the installer. Go the the python’s official site here.
Now restart the terminal and check again with both commands python —version
python3 --version
Or
use to install last version
brew install python3 && cp /usr/local/bin/python3 /usr/local/bin/python
Add the repository and update
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
Update the package list
apt-get update
Verify the updated Python packages list
apt list | grep python3.10
Install the Python 3.10 package using apt-get
sudo apt-get install python3.10
Add Python 3.8 & Python 3.10 to update-alternatives
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
Update Python 3 for point to Python 3.10
sudo update-alternatives --config python3
or
write in console >‘R.version.string’ to print out the R version.


Web Site Terms and Conditions of Use
1. Terms
By accessing this web site, you are agreeing to be bound by these web site Terms and Conditions of Use, all applicable laws and regulations, and agree that you are responsible for compliance with any applicable local laws. If you do not agree with any of these terms, you are prohibited from using or accessing this site. The materials contained in this web site are protected by applicable copyright and trade mark law.
2. Use License
-
Permission is granted to temporarily download one copy of the materials
(information or software) on ThumbnailDownload.com's web site for personal,
non-commercial transitory viewing only. This is the grant of a license,
not a transfer of title, and under this license you may not:
- modify or copy the materials;
- use the materials for any commercial purpose, or for any public display (commercial or non-commercial);
- attempt to decompile or reverse engineer any software contained on ThumbnailDownload.com's web site;
- remove any copyright or other proprietary notations from the materials; or
- transfer the materials to another person or "mirror" the materials on any other server.
- This license shall automatically terminate if you violate any of these restrictions and may be terminated by ThumbnailDownload.com at any time. Upon terminating your viewing of these materials or upon the termination of this license, you must destroy any downloaded materials in your possession whether in electronic or printed format.
3. Disclaimer
- The materials on ThumbnailDownload.com's web site are provided "as is". ThumbnailDownload.com makes no warranties, expressed or implied, and hereby disclaims and negates all other warranties, including without limitation, implied warranties or conditions of merchantability, fitness for a particular purpose, or non-infringement of intellectual property or other violation of rights. Further, ThumbnailDownload.com does not warrant or make any representations concerning the accuracy, likely results, or reliability of the use of the materials on its Internet web site or otherwise relating to such materials or on any sites linked to this site.
4. Limitations
In no event shall ThumbnailDownload.com or its suppliers be liable for any damages (including, without limitation, damages for loss of data or profit, or due to business interruption,) arising out of the use or inability to use the materials on ThumbnailDownload.com's Internet site, even if ThumbnailDownload.com or a ThumbnailDownload.com authorized representative has been notified orally or in writing of the possibility of such damage. Because some jurisdictions do not allow limitations on implied warranties, or limitations of liability for consequential or incidental damages, these limitations may not apply to you.
5. Revisions and Errata
The materials appearing on ThumbnailDownload.com's web site could include technical, typographical, or photographic errors. ThumbnailDownload.com does not warrant that any of the materials on its web site are accurate, complete, or current. ThumbnailDownload.com may make changes to the materials contained on its web site at any time without notice. ThumbnailDownload.com does not, however, make any commitment to update the materials.
6. Links
ThumbnailDownload.com has not reviewed all of the sites linked to its Internet web site and is not responsible for the contents of any such linked site. The inclusion of any link does not imply endorsement by ThumbnailDownload.com of the site. Use of any such linked web site is at the user's own risk.
7. Site Terms of Use Modifications
ThumbnailDownload.com may revise these terms of use for its web site at any time without notice. By using this web site you are agreeing to be bound by the then current version of these Terms and Conditions of Use.
8. Governing Law
Any claim relating to ThumbnailDownload.com's web site shall be governed by the laws of the State of New delhi without regard to its conflict of law provisions.
General Terms and Conditions applicable to Use of a Web Site.


Torque 2D - Fish Game Tutorial - Part 2
2. Moving our Fish
|
|
Figure 2.1.2
This is all the work we can do in the Level
Builder before touching a little bit of script. Because of this ability
to link a class in the Level Builder, this next step is very easy.
Before
we exit, we want to make sure we save our level properly. That way when we load
it up, our fish is already placed with its class already set. Save the level as
"myFishlevel".
Open the directory where you created your project and then open the game/gameScripts folder. This is where your game scripts should be located. Presently, you should only see a game.cs file in this location. (.cs is the Torque Script file extension). In this folder we can create additional script files to build up our game; we will begin with movement. Create a text file in this folder and name it "player.cs". Be sure you add the .cs extension so T2D will recognize it as a script file. Now you can open your newly created player.cs in any text editing program. (At the least, Windows users can right-click and choose Open With to use either Notepad or Wordpad. Mac users can control-click and choose Open With to use TextEdit). If you remember, we set our fish's class to PlayerFish. So we are going to add the following function to our player.cs.
function PlayerFish::onLevelLoaded(%this, %scenegraph) { }
Code Sample 2.3.1
As you may notice, we start with the keyword function, which tells T2D that we are beginning a function declaration. Then we follow with our class name PlayerFish. This attaches our function to the PlayerFish class. Since our fish is using the PlayerFish class, our fish will now have access to this function. Then we get to the actual function name (onLevelLoaded), which you might have guessed gets called when our fish gets loaded into the level. After the function name, we have two comma separated values inside of parenthesis. These are values that will be passed to this function, and which could be useful. The %this value represents the object that this function is being called on. That value is useful when we have multiple objects using the same class. It represents the specific instance of the class calling this function. The %scenegraph value is useful as well, since it represents our level object. Everything in our level is inside of the scenegraph object. Here is a breakdown of what our function script means.
function PlayerFish::onLevelLoaded(%this, %scenegraph) { }
Now it's time to do something inside of the script. Since it gets called when our fish is loaded into our level, we can store this instance of our fish to be used in our key responses. Add this line in between the curly braces ({ }).
$FishPlayer = %this;
Code Sample 2.3.2
What this does is grab the instance we are loading and store it in the $FishPlayer variable. In Torque Script a "$" before text means it is a global variable, and a "%" before text means it is a local variable. A local variable (like %this) will only exist within the calling function. Once the function ends, the variable gets destroyed. Think of it as a temporary variable. On the other hand, a global variable will persist outside of the function, and can be accessed in any script or anywhere in the game.
Now that we have stored the fish object, which will represent our player, we need the commands to bind our keys for movement. We will use the w, s, a, and d keys, so we need to make four separate script lines. Add these lines after our "$FishPlayer = %this;" line.
moveMap.bindCmd(keyboard, "w", "fishPlayerUp();", "fishPlayerUpStop();"); moveMap.bindCmd(keyboard, "s", "fishPlayerDown();", "fishPlayerDownStop();"); moveMap.bindCmd(keyboard, "a", "fishPlayerLeft();", "fishPlayerLeftStop();"); moveMap.bindCmd(keyboard, "d", "fishPlayerRight();", "fishPlayerRightStop();");
Code Sample 2.3.3
There is already an object called moveMap, and this object is what handles our key events when running our level. We use a function called bindCmd on our moveMap, and we pass it a few values. First, we specify that we are binding a command to our keyboard. We then specify which key we are binding. After that, we specify what function to call when the key is pressed, and our final value is what function to call when the key is released. So, for example, we bind the keyboard key w and when we press it fishPlayerUp() is called. Then, when we release the key, fishPlayerUpStop() is called to stop our action.
Now when our fish gets loaded, it will be stored in $FishPlayer and the w, s, a, and d keys will get bound. Next we need to create the functions that are called when we press the keys.
We are now finished putting script lines inside of our onLevelLoaded() function, but we still need some others. As we create these new functions, be sure not to put one function inside another one accidentally. The following functions should be placed after the ending curly brace ( } ) of our onLevelLoaded function.
function fishPlayerUp() { $FishPlayer.setLinearVelocityY( -15 ); }
Code Sample 2.4.1
Here is our fishPlayerUp() function. As you can see, we reference the fish by the stored value in $FishPlayer and call setLinearVelocityY() on it. This function will basically set its Y direction speed. Since we are setting it negative, it will go upward (because screen coordinates start at X = 0, Y = 0 at the top left corner of the screen, numbers on the Y axis get lower as you go higher up). We now need to add the next three functions for movement.
function fishPlayerDown() { $FishPlayer.setLinearVelocityY( 15 ); } function fishPlayerLeft() { $FishPlayer.setLinearVelocityX( -30 ); } function fishPlayerRight() { $FishPlayer.setLinearVelocityX( 30 ); }
Code Sample 2.4.2
These functions basically do the same thing. The down function sets the Y
velocity as a positive value. The left and right functions set the X velocity
instead of the Y velocity, to move horizontally. We are nearly done. We now
need to add the stop functions. The stop functions are very similar to our
movement functions, they simply set the appropriate velocity to zero. So, add
these four functions.
function fishPlayerUpStop() { $FishPlayer.setLinearVelocityY( 0 ); } function fishPlayerDownStop() { $FishPlayer.setLinearVelocityY( 0 ); } function fishPlayerLeftStop() { $FishPlayer.setLinearVelocityX( 0 ); } function fishPlayerRightStop() { $FishPlayer.setLinearVelocityX( 0 ); }
Code Sample 2.4.3
As you can see, the up and down functions set the Y velocity to zero and the left and right functions set the X velocity to zero. This will cause our fish to stop when the appropriate key is released.
Now your player.cs script file should look like this.
function PlayerFish::onLevelLoaded(%this, %scenegraph) { $FishPlayer = %this; moveMap.bindCmd(keyboard, "w", "fishPlayerUp();", "fishPlayerUpStop();"); moveMap.bindCmd(keyboard, "s", "fishPlayerDown();", "fishPlayerDownStop();"); moveMap.bindCmd(keyboard, "a", "fishPlayerLeft();", "fishPlayerLeftStop();"); moveMap.bindCmd(keyboard, "d", "fishPlayerRight();", "fishPlayerRightStop();"); } function fishPlayerUp() { $FishPlayer.setLinearVelocityY( -15 ); } function fishPlayerDown() { $FishPlayer.setLinearVelocityY( 15 ); } function fishPlayerLeft() { $FishPlayer.setLinearVelocityX( -30 ); } function fishPlayerRight() { $FishPlayer.setLinearVelocityX( 30 ); } function fishPlayerUpStop() { $FishPlayer.setLinearVelocityY( 0 ); } function fishPlayerDownStop() { $FishPlayer.setLinearVelocityY( 0 ); } function fishPlayerLeftStop() { $FishPlayer.setLinearVelocityX( 0 ); } function fishPlayerRightStop() { $FishPlayer.setLinearVelocityX( 0 ); }
Code Sample 2.4.4
We are almost ready to test. We have one final step before we can move our fish around. The player.cs script file has all of the appropriate functions, but it isn't being referenced anywhere right now. Without referencing it, the program won't know to use the code inside it. T2D doesn't automatically reference every .cs file in your folders. This gives you complete control and you can choose whether or not you want a script file referenced. When T2D references a script file it will "exec" (short for execute) the file. So we need to add a proper exec command to reference the player.cs file we created. Exec "player.cs" from "game.cs".
So your modified game.cs file should look like this.
//--------------------------------------------------------------------------------------------- // Torque 2D // Copyright (C) GarageGames.com, Inc. //--------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- // startGame // All game logic should be set up here. This will be called by the level builder when you // select "Run Game" or by the startup process of your game to load the first level. //--------------------------------------------------------------------------------------------- function startGame(%level) { exec("./player.cs"); Canvas.setContent(mainScreenGui); Canvas.setCursor(DefaultCursor); new ActionMap(moveMap); moveMap.push(); $enableDirectInput = true; activateDirectInput(); enableJoystick(); sceneWindow2D.loadLevel(%level); } //--------------------------------------------------------------------------------------------- // endGame // Game cleanup should be done here. //--------------------------------------------------------------------------------------------- function endGame() { sceneWindow2D.endLevel(); moveMap.pop(); moveMap.delete(); }
Code Sample 2.5.3
This startGame() function gets called when we test our level in the T2D Level Builder. As you can see, we now reference the player.cs file so when T2D runs it will include it.
Now before we run T2D again we need to be sure we save our changes to these files. Now play your level!
You should see all of the tool bars and Level Builder menus disappear, leaving only our fish. Now, try pressing our movement keys (a, s, w, and d). You should see the fish being moved in the appropriate direction!Congratulations! You have your fish moving around based on your keys. You should be getting a beginning feel of T2D scripting. When you're ready, move on to Part 3 and our Fish game takes another step.


For anyone that wants to share their digital media in a real location, Hexology is the social media app that puts your content into the #physicalworld.


Parijat Purohit
Yes, you landed in the right
place!
I am a motivational speaker, a placement consultant, a tech enthusiast (and a software
engineer) who loves coding and developing products for a living.
In my pastime, I also love helping young software engineers by providing my interview
cracking experiences.
I guess I used to be an electrical engineer, but that part in me is probably busy watching
rovers crawling on mars.