Jump to content


Photo

very specific question


  • Please log in to reply
10 replies to this topic

#1 Mr. RPG

Mr. RPG

    GMC's Forum Troll

  • GMC Member
  • 2671 posts
  • Version:GM:Studio

Posted 21 January 2012 - 07:13 PM

In my game, one of its biggest features, is that you can build towns by finding the 'blueprints' of the town's buildings and people. For example, when you have found the blueprint to 'Jack's Weapon Store' you will need several items to complete his house. First, you'll need himself, a case of wine, and a crate of weapons. Once you complete his house, you receive a gift or reward from whoever's house you built.

Now, 'Jack's Weapon Store' and any of the similar buildings are separate objects. So, how do I make it after when the player wishes to delete the building, that you cannot collect the reward again? (I am trying to stay away with global variables, because it sounds like I would require too many for this)

Is it possible to, at the Destroy event, make all new instances of a particular object have a new variable in its Create event?

Edited by Mr. RPG, 21 January 2012 - 10:24 PM.

  • 0

#2 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1323 posts
  • Version:GM8

Posted 21 January 2012 - 07:15 PM

Yes, you can. When the object is destroyed, put this in its destroy event:

global.newvar=true


In the object's create event

if global.newvar=true
{newvarhere=true}

  • 1

#3 Mr. RPG

Mr. RPG

    GMC's Forum Troll

  • GMC Member
  • 2671 posts
  • Version:GM:Studio

Posted 21 January 2012 - 07:18 PM

Yes, you can. When the object is destroyed, put this in its destroy event:

global.newvar=true


In the object's create event

if global.newvar=true
{newvarhere=true}


I said I didn't want to use global variables, because it would require so many. There are several buildings in the game. Probably in the end, there will be over 2 dozen.

That would be way too messy. There must be a easier way?
  • 0

#4 Sirosky

Sirosky

    GMC Member

  • GMC Member
  • 1323 posts
  • Version:GM8

Posted 21 January 2012 - 07:52 PM

What are you talking about? You only need one global variable for all of the objects, hence the "global." Posted Image
  • 0

#5 Mr. RPG

Mr. RPG

    GMC's Forum Troll

  • GMC Member
  • 2671 posts
  • Version:GM:Studio

Posted 21 January 2012 - 10:24 PM

What are you talking about? You only need one global variable for all of the objects, hence the "global." Posted Image


Ah, I was trying to make this more complicated than was needed. Thanks for your help!
  • 0

#6 Davido01

Davido01

    GMC Member

  • New Member
  • 905 posts

Posted 21 January 2012 - 10:30 PM

As to your problem you could always store the variables into a global list, not much better but slightly better.

Another alternative would be to have a controller object that stores all the variables locally for whether a reward has been collected or not from a certain building object, which each new instance refers to.

A quick look at the manual shows this, but it looks like more trouble than what its worth compared to doing one of the above methods or just having tons of globals.

object_event_add(ind,evtype,evnumb,codestr) To give the object a behavior we must define events for the object. You can only add code actions to events. You need to specify the object, the event type, the event number (use the constants that have been specified before for the event_perform() function). Finally you provide the code string that must be executed. You can add multiple code actions to each event.


EDIT: Based on the above comment, I have obviously misunderstood too.

EDIT2: Oh right, he was pertaining to your last question.

Edited by Davido01, 21 January 2012 - 10:33 PM.

  • 0

#7 @Alex@

@Alex@

    Retired GMC Reviewer

  • Reviewer
  • 3058 posts
  • Version:Unknown

Posted 21 January 2012 - 10:32 PM

You need a seperate global variable for each type of buidling do you not? Perhaps a global array where each object uses a unique number to as the index to the array. That way when the objectt is destroyed it can set the correct part of the array.
  • 0

#8 Mr. RPG

Mr. RPG

    GMC's Forum Troll

  • GMC Member
  • 2671 posts
  • Version:GM:Studio

Posted 21 January 2012 - 10:57 PM

You need a seperate global variable for each type of buidling do you not? Perhaps a global array where each object uses a unique number to as the index to the array. That way when the objectt is destroyed it can set the correct part of the array.


I am not understanding, what are you trying to suggest to me?
  • 0

#9 Davido01

Davido01

    GMC Member

  • New Member
  • 905 posts

Posted 22 January 2012 - 12:46 AM


You need a seperate global variable for each type of buidling do you not? Perhaps a global array where each object uses a unique number to as the index to the array. That way when the objectt is destroyed it can set the correct part of the array.


I am not understanding, what are you trying to suggest to me?


A list that is global essentially. With each one of the indexes being the variable for each building. Easier to handle than variables, but will still need the same number as the number of buildings there are.
  • 0

#10 Mr. RPG

Mr. RPG

    GMC's Forum Troll

  • GMC Member
  • 2671 posts
  • Version:GM:Studio

Posted 22 January 2012 - 01:03 AM



You need a seperate global variable for each type of buidling do you not? Perhaps a global array where each object uses a unique number to as the index to the array. That way when the objectt is destroyed it can set the correct part of the array.


I am not understanding, what are you trying to suggest to me?


A list that is global essentially. With each one of the indexes being the variable for each building. Easier to handle than variables, but will still need the same number as the number of buildings there are.


Can I see an example?
  • 0

#11 @Alex@

@Alex@

    Retired GMC Reviewer

  • Reviewer
  • 3058 posts
  • Version:Unknown

Posted 24 January 2012 - 12:20 PM

Arrays are variables too , in a way anyway. Make a global list

globalvar List ; // This will let you reference the list without using global.List

List[100000] = false ; // Initialise your array up to the total number of rewards you can recieve, this will fill the undeclared elements to 0 (aka false)

Now whenever you want to check to see if you recieve a reward check the approiate array element. If this is just for building buildings or collecting resources you can use the object_index of the object as a unique key to the array. E.G when a building is built and the reward collected

List[object_index] = true ;
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users