Hello am using game maker to create my project. My project has a start button and when you click it, the alarms will go off and run code which i set in the alarm for example.
Example, alarm[0] = 30 // set the timer
Now in alarm[0] we add code.
Create (x,y ,player); // code i want to run when i click the start button.
However game maker only has 11 alarms i wanted to know if there were ways to create more alarms like alarm[14] and so on.
An alarm is just a variable.
Some scripts for custom alarms:
script custom_alarms_initialize. Call it from Create event
/// custom_alarms_initialize(alarms_number)
for (var i=0; i<argument0; i++)
{
custom_alarm[i, 0] = -1;
custom_alarm[i, 1] = -1;
}
script custom_alarms_step. Call it from Step Begin event
/// custom_alarms_step()
var sz = array_height_2d(custom_alarm);
for (var i=0; i<sz; i++)
{
if custom_alarm[i, 0] != -1
{
custom_alarm[i, 0]--; // Counter
if custom_alarm[i, 0] = 0
{
custom_alarm[i, 0] = -1;
if script_exists(custom_alarm[i, 1])
script_execute(custom_alarm[i, 1]);
}
}
}
script custom_alarm_set. Use it for start alarm
/// custom_alarm_set(alarm, time, script)
var sz = array_height_2d(custom_alarm);
if argument0 < sz
{
custom_alarm[argument0, 0] = max(-1, argument1);
custom_alarm[argument0, 1] = argument2;
}
else
{
show_message("Out of range (alarm " + string(argument0) + "). Max alarm id: " + string(sz - 1));
}
script custom_alarm_get_current. Use if you want get current value.
/// custom_alarm_get_current(alarm)
var sz = array_height_2d(custom_alarm);
if argument0 < sz
{
return custom_alarm[argument0, 0];
}
else
{
show_message("Out of range (alarm " + string(argument0) + "). Max alarm id: " + string(sz - 1));
}
Example of use:
alarm_start(5, room_speed * 10, your_action);
where your_action - name of the script which will be executed.
P.S. This code is for GameMaker Studio, not for GM 8.
P.P.S. Link to example: click
Related
Is it possible to render in one progressbar the progress of 2 nested tasks?
I mean, if I have to read lines from several files in several directories. I have this snippet code:
EDIT:
final int steps = directories.size();
Task<Integer> task2 = new Task<Integer>() {
/**
*/
#Override
protected Integer call() throws Exception {
int len = files.length;
updateProgress(0, len);
for(int i = 0; i < files.length; i++) {
final String filename = files[i].getName();
final String file = files[i].getPath();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
}
String currentLine = null;
while ((currentLine = br.readLine()) != null) {
readlines(currentLine, filename);
}
} catch (IOException xs) {
xs.getMessage();
}
System.out.println("******* Working on: " + file + " ******************************");
updateProgress(i + 1, files.length);
}
System.out.println("done: " + directoryName);
return len;
}
};
task2.setOnRunning(r -> {
DoubleBinding totalProgress = null;
for(int i = 0; i < steps; i++) {
DoubleBinding increment = task2.progressProperty().divide(steps);
if (totalProgress == null) {
totalProgress = increment;
} else {
totalProgress = totalProgress.add(increment);
}
}
progressBar.progressProperty().bind(totalProgress);
status.textProperty().bind(task2.stateProperty().asString());
statusProcess.textProperty().bind(Bindings.when(totalProgress.isEqualTo(-1))
.then("0.00")
.otherwise(task2.progressProperty().multiply(100.00).asString("%.02f %%")));
console.textProperty().bind(task2.messageProperty());
});
new Thread(task2).start();
I am enable to access progress bar but as long as I have directories, the progress bar will restart to 0 and will check for files into the next directory and then populate the progress bar until 1 and then restart to 0 if there is another directory.
How can I do if I want to display these 2 tasks in one as I don't want to restart from 0 when the next directory is reading. If I have for example 4 directories, I expect to see a moving the progressbar until its quarter and so on.
Is anybody as an idea what I am doing wrong?
You can do something like
progressBar.progressProperty().bind(Bindings.createDoubleBinding(
() -> Math.max(0, task1.getProgress()) / 2 + Math.max(0, task2.getProgress()) /2 ,
task1.progressProperty(), task2.progressProperty());
If you can easily estimate or compute the relative times each task will take, you can weight the progress of each task accordingly, instead of simply averaging them as in the code above.
I have the following problem:
When I press the pause button my characters jumps at the same time, the pause button being a VIRTUAL KEY and the jump button is keyboard_mouse_button_check(mb_left) .
I am trying to:
be able to press the pause button without making the character jump at the same time.
Obj_pause
Create Event
global.pause = 0;
Step Event
if keyboard_check_pressed(vk_space) and !global.death and !global.stop
global.pause = !global.pause
Obj_player
Create Event
// Initialize Variables
global.stop = 0;
previously_paused = false;
global.bigscore = 0;
global.col = true;
global.cartof = 0;
grav = 0.2;
hsp = 0;
vsp = 0;
jumpspeed = 4;
movespeed = 4;
antigrav = true;
jumps = 0;
jumpsmax = 2;
delay = 3;
alarm[3] = delay;
Step Event
if (global.pause) or (global.death) exit; // Pause
// Get the player's input
key_jump = mouse_check_button(mb_left);
// React to inputs
hsp = 0;
if vsp < 10
vsp += grav;
if place_meeting(x, y + 1, obj_wall)
jumps = jumpsmax;
// Double jump
if (key_jump) && (jumps > 0) && (!previously_paused)
{
jumps -= 1;
vsp = -jumpspeed;
previously_paused = global.pause;
}
// Fly
else if (jumps == 0)
{
key_jump = mouse_check_button(mb_left);
if key_jump
vsp -= 0.4
}
if global.col
{
// Horizontal Collision
if (place_meeting(x+hsp, y, obj_wall))
{
while (!place_meeting(x + sign(hsp), y, obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
x += hsp;
}
// Vertical Collision
if (place_meeting(x, y + vsp, obj_wall))
{
while (!place_meeting(x, y + sign(vsp), obj_wall))
{
y += sign(vsp);
}
vsp = 0;
}
y += vsp;
// Exit the game or restart
if keyboard_check(ord("P"))
game_restart();
if keyboard_check(vk_space)
alarm[1] = room_speed;
// Score
if background_hspeed[0] < 0
global.cartof += 10;
I have tried:
Check if I press the pause button don't do the jump To change key_jump to be equal 0 when I click on the pause button. When mouse is over the pause button to dezactivate the mouse ArchbishopDave Method
I am using:
GM:S 1.4
GameMaker Language (GML) or Drag and Drop (DnD)
Did you read event order? Step events will be runned before Keyboard and Mouse events (and virtual buttons too). So if you checked jump button in Step event, and only after it will be pressed virtual key, then your character always will jump.
You need change order of checks. For example, you can manually check, is pressed virtual key or not, before jump (check, is mouse inside coords of virtual key or not), something like this:
key_jump = mouse_check_button(mb_left);
if point_in_rectangle(device_mouse_x_to_gui(0), device_mouse_y_to_gui(0), virt_left, virt_top, virt_right, virt_bottom)
key_jump = false;
where virt_left, virt_top, virt_right, virt_bottom is coords of your virtual button.
There are many ways for improve it, but all depend on your code/architecture (depth of objects, creation order of instances, etc), so I can't give a finihsed perfect solution. If you will have a problem with fix, just share your project and I'll help.
I am trying to load a java class to oracle as a function. In the server I managed to use loadjava as below:
C:\Users\n12017>loadjava -user USER1/passw E:\JAVA_repository\SOOSProjects\Mehmet_java_2db_trial\classes\mehmet_java_2db_trial\kondrakk.class
And in the oracle db side:
create or replace function ngram_kondrakk(src in varchar2, trg in varchar2)
return float
as language java
name 'mehmet_java_2db_trial/kondrakk.getDistance(java.lang.string, java.lang.string) return java.lang.float';
/
However, when I apply the query as below, I got error. (As a result of the query I am expecting a similarity score of 1 since two identical strings are compared)
select ngram_kondrakk('mehmet','mehmet') from dual;
Here is the error:
ORA-29532: Java call terminated by uncaught Java exception: System error : java/lang/UnsupportedClassVersionError
29532. 00000 - "Java call terminated by uncaught Java exception: %s"
*Cause: A Java exception or error was signaled and could not be
resolved by the Java code.
*Action: Modify Java code, if this behavior is not intended.
Finally, here is the code that I am trying to use:
package mehmet_java_2db_trial;
public class kondrakk {
public static float getDistance(String source, String target) {
final int sl = source.length();
final int tl = target.length();
if (sl == 0 || tl == 0) {
if (sl == tl) {
return 1;
}
else {
return 0;
}
}
int n=3;
int cost = 0;
if (sl < n || tl < n) {
for (int i=0,ni=Math.min(sl,tl);i<ni;i++) {
if (source.charAt(i) == target.charAt(i)) {
cost++;
}
}
return (float) cost/Math.max(sl, tl);
}
char[] sa = new char[sl+n-1];
float p[]; //'previous' cost array, horizontally
float d[]; // cost array, horizontally
float _d[]; //placeholder to assist in swapping p and d
//construct sa with prefix
for (int i=0;i<sa.length;i++) {
if (i < n-1) {
sa[i]=0; //add prefix
}
else {
sa[i] = source.charAt(i-n+1);
}
}
p = new float[sl+1];
d = new float[sl+1];
// indexes into strings s and t
int i; // iterates through source
int j; // iterates through target
char[] t_j = new char[n]; // jth n-gram of t
for (i = 0; i<=sl; i++) {
p[i] = i;
}
for (j = 1; j<=tl; j++) {
//construct t_j n-gram
if (j < n) {
for (int ti=0;ti<n-j;ti++) {
t_j[ti]=0; //add prefix
}
for (int ti=n-j;ti<n;ti++) {
t_j[ti]=target.charAt(ti-(n-j));
}
}
else {
t_j = target.substring(j-n, j).toCharArray();
}
d[0] = j;
for (i=1; i<=sl; i++) {
cost = 0;
int tn=n;
//compare sa to t_j
for (int ni=0;ni<n;ni++) {
if (sa[i-1+ni] != t_j[ni]) {
cost++;
}
else if (sa[i-1+ni] == 0) { //discount matches on prefix
tn--;
}
}
float ec = (float) cost/tn;
// minimum of cell to the left+1, to the top+1, diagonally left and up +cost
d[i] = Math.min(Math.min(d[i-1]+1, p[i]+1), p[i-1]+ec);
}
// copy current distance counts to 'previous row' distance counts
_d = p;
p = d;
d = _d;
}
// our last action in the above loop was to switch d and p, so p now
// actually has the most recent cost counts
System.out.println(1.0f - (p[sl] / Math.max(tl, sl)));
return 1.0f - (p[sl] / Math.max(tl, sl));
}
}
Please HELP!
Thanks in advance...
When compiling Java classes to load into an Oracle database, be sure that you compile your Java classes to run with the JVM inside the Oracle database.
The version of Java that comes with an Oracle database is typically out of date compared to the current Java: expect to be using Java 1.4 with Oracle 10g and 1.5 with 11g. Your best bet is to use the Java compiler that ships with the database, but if you can't do that, use -target 1.5 or suchlike to force the compiler to compile classes to run on Java 1.5.
Your plsql wrapper function has "/"
...mehmet_java_2db_trial/kondrakk.getDistance...
replace / with . [dot]
Check the docs
and as it was already mentioned - sync JVM of compilation with JVM for run-time( which will be Oracle JVM that is "attached" to DB)
I'm developing an Android APP that connects to Google Calendar using GData API for Google Calendar in Java. So far I've managed to create events but I could only set the title, description and time.
Does anybody know where I can find a reference or a sample with all the parameters I can set to an event?
I leave you some code of what I've achieved so far.
CalendarService calendarService = new CalendarService("CalendarAPP");
calendarService.setUserCredentials(<username>, <password>);
URL postUrl = new URL("https://www.google.com/calendar/feeds/<GMAIL ACCOUNT>/private/full");
CalendarEventEntry myEntry = new CalendarEventEntry();
myEntry.setTitle(new PlainTextConstruct("Tennis with Beth"));
myEntry.setContent(new PlainTextConstruct("Meet for a quick lesson."));
DateTime startTime = DateTime.now();
DateTime endTime = DateTime.now();
When eventTimes = new When();
eventTimes.setStartTime(startTime);
eventTimes.setEndTime(endTime);
myEntry.addTime(eventTimes);
CalendarEventEntry insertedEntry = connection.getCalendarService().insert(postUrl, myEntry);
Thanks in advance.
Mikywan.
GData for Google Calendar it's pretty damn good. For every property you may want to set or get, there is a Getter and a Setter defined. You just have to look for the setter/getter on the event entry that suits the data you want access.
I leave an example of how to show on the console almost all the data you may want to.
Enjoy!
private static void showCalendarEventEntry(CalendarEventEntry entry) {
assert entry != null;
System.out.println("-------------------------------------------");
System.out.println("START showCalendarEventEntry");
System.out.println("");
System.out.println("ID: " + entry.getId());
System.out.println("TITLE: "+entry.getTitle().getPlainText());
System.out.println("DESCRIPTION: "+entry.getPlainTextContent());
System.out.println("LOCATION: "+entry.getLocations().get(0).getValueString());
System.out.println("");
System.out.println("TIMES");
if (entry.getTimes().size() > 0) {
When eventTimes = entry.getTimes().get(0);
if (eventTimes.getStartTime().isDateOnly()) {
System.out.println("\tWHEN: ALL DAY");
} else {
System.out.println("\tWHEN: TIME");
}
if (entry.getRecurrence() != null)
System.out.println("\tRECURRENCE: "+entry.getRecurrence().toString());
System.out.println("\tSTART TIME: "+eventTimes.getStartTime());
System.out.println("\tEND TIME: "+eventTimes.getEndTime());
}
System.out.println("");
System.out.println("PARTICIPANTS");
System.out.println("\t"+(entry.getParticipants().size()) + " PARTICIPANTS");
if (entry.getParticipants().size() > 0){
for (int i=0; i<entry.getParticipants().size(); i++) {
EventWho participant = entry.getParticipants().get(i);
System.out.println("\t\tPARTICIPANT "+participant.getValueString());
System.out.println("\t\t\tTYPE: "+participant.getAttendeeType());
System.out.println("\t\t\tSTATUS: "+participant.getAttendeeStatus());
}
if (entry.isGuestsCanInviteOthers())
System.out.println("\tGUESTS CAN INVITE OTHERS: ");
if (entry.isGuestsCanModify())
System.out.println("\tGUESTS CAN MODIFY");
if (entry.isGuestsCanSeeGuests())
System.out.println("\tGUESTS CAN SEE GUESTS");
}
//REMINDERS
System.out.println("");
System.out.println("REMINDERS");
System.out.println("\t"+entry.getReminder().size()+" REMINDERS");
if (entry.getReminder().size() > 0) {
for (int i=0; i<entry.getReminder().size(); i++) {
Reminder reminder = entry.getReminder().get(i);
System.out.println("\t\tREMINDER "+i);
System.out.println("\t\t\tMETHOD: "+reminder.getMethod().toString());
System.out.println("\t\t\tDAYS: "+reminder.getDays());
System.out.println("\t\t\tHOURS: "+reminder.getHours());
System.out.println("\t\t\tMINUTES: "+reminder.getMinutes());
}
}
//VISIBILITY
System.out.println("");
System.out.println("VISIBILITY: "+entry.getVisibility().getValue());
System.out.println("");
System.out.println("END showCalendarEventEntry");
System.out.println("-------------------------------------------");
}
I am a little stuck and need some advice/help.
I have a progress bar:
<mx:ProgressBar id="appProgress" mode="manual" width="300" label="{appProgressMsg}" minimum="0" maximum="100"/>
I have two listener functions, one sets the progress, and one sets the appProgressMsg:
public function incProgress(e:TEvent):void {
var p:uint = Math.floor(e.data.number / e.data.total * 100);
trace("Setting Perc." + p);
appProgress.setProgress(p, 100);
}
public function setApplicationProgressStep(e:TEvent):void {
trace("Setting step:" + e.data);
appProgressMsg = e.data;
}
I want to reuse this progress bar alot. And not necessarily for ProgressEvents, but when going through steps.
For instance, I loop over a bunch of database inserts, and want to undate the progress etc.
Here is a sample:
public function updateDatabase(result:Object):void {
var total:int = 0;
var i:int = 0;
var r:SQLResult;
trace("updateDatabase called.");
for each (var table:XML in this.queries.elements("table")) {
var key:String = table.attribute("name");
if (result[key]) {
send(TEvent.UpdateApplicationProgressStep, "Updating " + key);
i = 1;
total = result[key].length;
for each (var row:Object in result[key]) {
//now, we need to see if we already have this record.
send(TEvent.UpdateApplicationProgress, { number:i, total: total } );
r = this.query("select * from " + key + " where server_id = '" + row.id + "'");
if (r.data == null) {
//there is no entry with this id, make one.
this.query(table.insert, row);
} else {
//it exists, so let's update.
this.update(key, row);
}
i++;
}
}
}
}
Everything works fine.
That is, the listener functions are called and I get trace output like:
updateDatabase called.
Setting step:Updating project
Setting Perc 25
Setting Perc 50
Setting Perc 75
Setting Perc 100
The issue is, only the very last percent and step is shown. that is, when it's all done, the progress bar jumps to 100% and shows the last step label.
Does anyone know why this is?
Thanks in advance for any help,
Jason
The new code, which works awesomely I might add:
public function updateDatabase(result:Object, eindex:int = 0, sindex:int = 0 ):void {
var total:int = 0;
var i:int = 0;
var j:int;
var r:SQLResult;
var table:XML;
var key:String;
var elems:XMLList = this.queries.elements("table");
var startTime:int = getTimer();
var row:Object;
for (i = eindex; i < elems.length(); i++) {
table = elems[i];
key = table.attribute("name");
if (!result[key])
continue;
total = result[key].length;
send(TEvent.UpdateApplicationProgressStep, "Updating " + key);
for (j = sindex; j < result[key].length; j++) {
if (getTimer() - startTime > 100) {
setTimeout(updateDatabase, 100, result, i, j);
send(TEvent.UpdateApplicationProgress, { number:j, total: total } );
return;
}
row = result[key][j];
r = this.query("select * from " + key + " where server_id = '" + row.id + "'");
if (r.data == null) {
//there is no entry with this id, make one.
this.query(table.insert, row,false);
} else {
//it exists, so let's update.
this.update(key, row,false);
}
}
send(TEvent.UpdateApplicationProgress, { number:1, total: 1 } );
}
}
Flash is single threaded. The display will not update until your function returns. For this reason, you should never have any code that runs for longer than about 100ms (1/10th of a second), otherwise the UI (or even the entire browser) will appear to be locked up.
The general solution is to split up your work over multiple frames, here is some pseudo-code:
function doWork(arg1:Obj, arg2:Obj, start:int=0) {
var startTime = getTimer(); // store starting time
for(i=start; i<length; i++) {
if(getTimer() - startTime > 100) { // see if we've been working too long
trace("Current progress: "+(i/length * 100)+"%");
updateProgress( i / length );
setTimeout(doWork, 100, arg1, arg2, i); // schedule more work to be done
return; // stop current loop
}
trace("Working on item "+i);
// processing here
}
trace("All work done");
}
doWork(data1, data2); // start the work
Your pseudo-code works for updating the progress bar however in my case my "work" was copying of files from DVD to the appStorageDirectory which seem to reintroduce the same issue that your work around resolved - the progress bar now does not update
Here is my hack of your solution
function doWork(arg1:int, arg2:int, start:int=0) {
var startTime = getTimer(); // store starting time
for(var i:int=start; i<arg2; i++) {
if(getTimer() - startTime > 100 ) { // see if we've been working too long
trace("Current progress: "+(i/arg2 * 100)+"%");
setTimeout(doWork, 100, i, arg2, i); // schedule more work to be done
return; // stop current loop
}
trace("Working on item "+i);
dispatchEvent(new progressMadeEvent("incrementChange",i,arg2))
var dir:String = copyRes[i].nativePath.toString().split(OSSep).pop()
copyRes[i].copyTo(appStore.resolvePath(dir)) // copies dir from DVD to appStorageDir
}
trace("All work done");
}