Author Topic: (no subject)  (Read 3048 times)

Dragonmaster

  • Member
  • *
  • Posts: 11
    • View Profile
(no subject)
« on: June 24, 2005, 02:24:48 PM »
I have an idea for a minigame where you as a player has 30-45 seconds to unlock a lock by choosing the correct picks for a lock combination.  The main trouble I encounter with this minigame is the countdown.  I can create a countdown easily
Code: [Select]
for(i!=30;i!>0;i!--)
{
  i = CastLit(i!)
  Text(1,1,i)
  delay(1)
}
I think the best place to implement this countdown, would be in a thread.  If I understand the way RPGCode implements threads, if I created a thread for the countdown display, it would also allow the player to interact with the minigame while the countdown countinues.  I was wondering if anyone could guide me with this endeavor.  Specifically how would the program that creates the thread know when the countdown has reached zero.  Any help is appreciated.

Thanks
Dragonmaster
« Last Edit: June 24, 2005, 02:26:10 PM by Dragonmaster »

Aminaga

  • Member
  • *
  • Posts: 1665
    • View Profile
    • http://ultimategamingproductions.net
(no subject)
« Reply #1 on: June 24, 2005, 02:48:17 PM »
Cool. Do you know if it would work in TK2 perhaps? Smile
« Last Edit: December 31, 1969, 06:00:00 PM by Aminaga »
<span style=\'font-size:16pt;line-height:100%\'><a href=\'http://ultimategamingproductions.net\' target=\'_blank\'>WWW.ULTIMATEGAMINGPRODUCTIONS.NET</a></span>

Xorlak

  • Administrator
  • Member
  • *****
  • Posts: 2225
    • View Profile
    • http://darkagegames.net
(no subject)
« Reply #2 on: June 26, 2005, 04:03:00 PM »
I wouldn't try it in TK2...

Yes, if you set that program as a thread, it should work.  If you make i! a global variable, then any exterior program will be able to check it and see when it reaches 0.  Also, you might want to draw to the CnvRenderNow! canvas so that your character can walk around and the numbers will scroll with the screen.  Delay() will be a problem though, since I think a delay() call in a thread will still freeze the entire game, but you could substitute it with a method that wastes time in a loop or something.

EDIT: Or you could make the thread go to sleep for a second. Haven't messed with that yet...

Code: [Select]
counter! = 30
while(counter! > 0)
{
  clear(cnvRenderNow!)
  text(1,1,counter!, cnvRenderNow!)
  // waste time method here...
  counter!--
}
« Last Edit: June 26, 2005, 04:04:14 PM by Xorlak »

Aminaga

  • Member
  • *
  • Posts: 1665
    • View Profile
    • http://ultimategamingproductions.net
(no subject)
« Reply #3 on: June 27, 2005, 11:33:08 AM »
Quote from: "Xorlak"
I wouldn't try it in TK2...


k Let's see what Dragonmaster has to say then... Wink
« Last Edit: June 27, 2005, 11:33:38 AM by Aminaga »
<span style=\'font-size:16pt;line-height:100%\'><a href=\'http://ultimategamingproductions.net\' target=\'_blank\'>WWW.ULTIMATEGAMINGPRODUCTIONS.NET</a></span>

Dragonmaster

  • Member
  • *
  • Posts: 11
    • View Profile
(no subject)
« Reply #4 on: June 27, 2005, 11:40:33 AM »
I tried to do this
Code: [Select]
////caller program////
choice!=1
hThread! = Thread("countdown.prg",1)
While(i!>0)
{
  highlightPick(choice!)
  Wait(input$)
  SetChoice(input$)
 }
What I want this to do is start the countdown thread.  While the thread is counting down, allow the user to choose which pick to use per section(tumbler)

Code: [Select]
//Thread//
i! = 30
While(i!>0)
{
  clear(cnvRenderNow!)
  ColorRGB(254,36,0)
  FontSize(30)
  Bold("on")
  i$ = CastLit(i!)
  Text(1,1,i$,cnvRenderNow!)
  ColorRGB(0,0,0)
  Bold("off")
  FontSize(20)
 drawCanvas(cnvRenderNow!, 0,0)
 threadSleep(hThread!, 1)
 i--
}
If i run the caller program the Text is not displaying.  Otherwise if I run just the countdown prg it displays the text perfectly.  Not sure why.
« Last Edit: December 31, 1969, 06:00:00 PM by Dragonmaster »

Colin

  • Member
  • *
  • Posts: 299
    • View Profile
(no subject)
« Reply #5 on: June 27, 2005, 01:23:00 PM »
You're using cnvRenderNow wrong. Don't try to draw it; use renderNow(). For reasons that probably aren't obvious to you, threads don't run during other programs either. You should be thankful they don't. Use conventional countdown methods for a countdown within a program.

For a delay, you can use threadSleep(getThreadId(), x!).
« Last Edit: June 27, 2005, 01:26:11 PM by Colin »
— Colin

Dragonmaster

  • Member
  • *
  • Posts: 11
    • View Profile
(no subject)
« Reply #6 on: June 27, 2005, 02:18:47 PM »
So basically, rpgcode threads are not really threads at all.  I do understand threads, having a bachelors degree in computer science.
« Last Edit: December 31, 1969, 06:00:00 PM by Dragonmaster »

Colin

  • Member
  • *
  • Posts: 299
    • View Profile
(no subject)
« Reply #7 on: June 27, 2005, 08:13:35 PM »
They're threads all right. Although the origin of the way they work is not to protect users, it's certainly a good reason for them not running during programs. Threads are generally for working in the background in practical application: you would never use a thread to modify global things, like drawing text on the screen.

It would probably be too slow to run them during programs now, and I can foresee many problems with conflicts in people's code not fully understanding threading concepts, but if the speed is sufficiently increased in the next version, we'll look into trying it out. I hope you can work around it in the meantime. Sorry for the inconvenience.
« Last Edit: June 27, 2005, 08:28:13 PM by Colin »
— Colin

Dragonmaster

  • Member
  • *
  • Posts: 11
    • View Profile
(no subject)
« Reply #8 on: June 28, 2005, 06:16:43 AM »
I have to disagree.  According to your comment
Quote
For reasons that probably aren't obvious to you, threads don't run during other programs either.

But I define threads as "processes that can run concurrently." concurrently doesnt necessarily mean simultaneously.  Anyways Im not here to argue, Id rather try to sort out a solution to this.  Thanks.
« Last Edit: December 31, 1969, 06:00:00 PM by Dragonmaster »

Colin

  • Member
  • *
  • Posts: 299
    • View Profile
(no subject)
« Reply #9 on: June 28, 2005, 09:36:02 AM »
Where did I say anything about concurrence or simultaneity? I'm going to have to stand by that 'comment' too, because you're proved it to be true. If you're making threads that modify globals things (and drawing text is indeed global), that's not good at all?regardless of whether they're running concurrently or simultaneous.

If you don't want to argue, then don't argue. It's ridiculous when people respond to you with things that are, in fact, arguments then tell you not to reply. If only it were that easy, eh?

The timer code DTS showed elsewhere will work for you, if you modify it slightly so it doesn't use cnvRenderNow!
« Last Edit: June 28, 2005, 09:37:57 AM by Colin »
— Colin

Dragonmaster

  • Member
  • *
  • Posts: 11
    • View Profile
(no subject)
« Reply #10 on: June 28, 2005, 11:55:52 AM »
I never asked you not to reply, in fact I expected it. But the statement
Quote
threads don't run during other programs either

, to me at least, implies concurrency.   I never argued with you about the nastiness of modifing global things in threads. But I couldnt think of another way. Maybe i misunderstood you. If thats the case I apologize. Before I started this minigame,  I thought I remebered you, or another developer, mentioning timer functions but I couldn't find the documentation to back up my memory.
« Last Edit: December 31, 1969, 06:00:00 PM by Dragonmaster »

Aminaga

  • Member
  • *
  • Posts: 1665
    • View Profile
    • http://ultimategamingproductions.net
(no subject)
« Reply #11 on: June 28, 2005, 11:59:52 AM »
Dragonmaster, I can see you're really getting pissed off, so why don't you know the facts so you know for future referenses:

[facts]Colin is annoying.[/facts]

Heh. No offense to Colin. Just seems like that when you always correct our typing, make comments on what we post, etc.  -_-
« Last Edit: June 28, 2005, 12:00:37 PM by Aminaga »
<span style=\'font-size:16pt;line-height:100%\'><a href=\'http://ultimategamingproductions.net\' target=\'_blank\'>WWW.ULTIMATEGAMINGPRODUCTIONS.NET</a></span>

Dragonmaster

  • Member
  • *
  • Posts: 11
    • View Profile
(no subject)
« Reply #12 on: June 28, 2005, 12:21:45 PM »
Ive been here for over a year now, and I've spoken with Colin a few times before.  While I have not agreed with a couple of things done with rpgcode, I havent encountered him to be rude or annoying.  He just states his opinions just as I do mine. In fact I usually enjoy trying to work with him.  I say trying because its hard to grab his attention to help you out. heh
« Last Edit: December 31, 1969, 06:00:00 PM by Dragonmaster »

Aminaga

  • Member
  • *
  • Posts: 1665
    • View Profile
    • http://ultimategamingproductions.net
(no subject)
« Reply #13 on: June 28, 2005, 12:48:32 PM »
Quote from: "Dragonmaster"
Ive been here for over a year now


Points to Dragonmaster's date of joining MS. Heh. j/k
« Last Edit: December 31, 1969, 06:00:00 PM by Aminaga »
<span style=\'font-size:16pt;line-height:100%\'><a href=\'http://ultimategamingproductions.net\' target=\'_blank\'>WWW.ULTIMATEGAMINGPRODUCTIONS.NET</a></span>