Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Timer / function problem

Author
Message
DarkByNight
15
Years of Service
User Offline
Joined: 16th Jul 2009
Location: Thailand
Posted: 5th Jun 2011 10:12
Hello, this is my first post in newcommers, with probably more to come since I am now delving into 2d game development.
First of all, here is my main code:


And here is my spell button code:


Now, my problem is that I want the player to cast a spell when he clicks the button labeled Circle of Spikes, and this works fine, except something is off with the timer, it kicks off all the code in the even at once instead of waiting for the timer.
Anyway, my main problem is that if I click the button again, the game just freezes with no error.
Can anyone see what I'm doing wrong please?
Thank you very much in advance.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 5th Jun 2011 11:03
Hi Darkbynight, the first thing I'm going to suggest is to use two variables for the timer. I haven't tested your code because I don't have your images and I'm too lazy to put my own in but as "tim" is only set to "timer()" once then I think "until Elapsed = 1" will only work once because you aren't repeatedly getting the timer() value.
So try adding

and then add
in your while loop, right above repeat

and
at the end of your repeat loop

Oh and replace the variable tim with new_t

This should allow multiple clicks of the "Circle of spikes".

So try that and report back what happens.

Also, try getting rid of the /1000 and then check for "until elapsed > 1000"

Hope all of this makes sense

A clever person solves a problem, a wise person avoids it - Albert Einstein
DarkByNight
15
Years of Service
User Offline
Joined: 16th Jul 2009
Location: Thailand
Posted: 5th Jun 2011 14:23
Ahh well now I can use it multiple times, however none of the graphics updates when it starts, and I never get the "The program got to this point" message. I am uploading the whole thing, I hope you can guide me to making this thing work.
Thank you so mumch for your help!

Attachments

Login to view attachments
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 5th Jun 2011 15:00 Edited at: 5th Jun 2011 15:09
Quote: "Thank you so mumch for your help!"

You're welcome, however I might take me a day or two to get around to going through your code, I have a lot on my plate at the moment, but I should have an answer for you within two days

What you could try though is to back up your project and then experiment around with your code. If this is the kind of game I think it is then you will probably benefit from using user-defined-types (UDTs) and the "SPRITE" command might be worth looking into as well.

I decided to have a quick look anyway, try this as your main source:



Is that what you were after?

A clever person solves a problem, a wise person avoids it - Albert Einstein
DarkByNight
15
Years of Service
User Offline
Joined: 16th Jul 2009
Location: Thailand
Posted: 6th Jun 2011 05:53 Edited at: 6th Jun 2011 07:35
Brilliant!!
Very much obliged!
That worked like a charm.
I must admit, I was very close to the solution because I was wondering why I didn't see old_t in the code other than setting it to new_t, I just didn't know how to use it to make it work but after seeing you do it, it is crystal clear.
This all was just a test invironment I do before every idea solidifies to get a basic groundwork done, I have clear ideas for this game but it'll be a tad more advanced than pushing a button, now I just need to refine all this code into my idea for the game!
That's the exciting part!

EDIT: After trying to get it into a function and everything breaking, I decided to use Shaun's timer plugin, after about 10 minutes work later, I got everything working beautifully!
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 6th Jun 2011 09:30
Glad it all worked out

A clever person solves a problem, a wise person avoids it - Albert Einstein

Login to post a reply

Server time is: 2024-11-16 21:39:18
Your offset time is: 2024-11-16 21:39:18