Jump to content

Photo

Divide by 4


  • Please log in to reply
11 replies to this topic

#1 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 24 May 2018 - 08:25 PM

I want to have a message string that changes based on the number of times Link collected item X.

 

And I want it to be divided by 4.

If Link has collected 80 of that item, I want the message string to say he collected 20.

If Link has collected 96 of that item, I want the message string to say he collected 24.

If Link has collected 100 of that item, I want the message string to say he collected 25.

etc.

 

Any ideas for the best way to do this?

 

EDIT: Maybe just forget the message string and have a secondary counter that goes up by one every time the first counter goes up by 4?


Edited by Cukeman, 25 May 2018 - 08:25 AM.


#2 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 25 May 2018 - 12:29 AM

Something like this should be all you need for that:

import "string.zh"

int count = 65;
int str[64] = "Hello Number \0"; //...

//puts count into str
{
  int countDiv4 = (count / 4) << 0;
  int n = itoa(str, 13, countDiv4);
  str[13 + n] = 0; //null terminate
}

//str should now read "Hello Number 16"
// *Note if the desired string would be : "Hello " + count + " Number" you'd need to concatenate strings or strcpy the tail of the string.


#3 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 25 May 2018 - 03:03 AM

What does the 64 and 65 mean in your code?



#4 Lüt

Lüt

    Germanize

  • Members
  • Real Name:Steve
  • Location:Chicago

Posted 25 May 2018 - 04:00 AM

What does the 64 and 65 mean in your code?

You divide one by 4 to get the other:
Spoiler
Ich habe keine Ahnung.

#5 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 25 May 2018 - 04:41 AM

What does the 64 and 65 mean in your code?


[64] is the size of the string.

#6 Avaro

Avaro

    o_o

  • Members
  • Real Name:Robin
  • Location:Germany

Posted 25 May 2018 - 07:06 AM

He probably meant a message string in the string editor, not a script string?



#7 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 25 May 2018 - 10:51 AM

I'm still confused.



#8 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 25 May 2018 - 06:15 PM

Sizes are all arbitrary; you just need to convert an integer value to a string representation of that value. Here's the same pony show but slightly different with more explanations:
//"If Link has collected 80 of that item, I want the message string to say he collected 20."
int num = 80/4; // == 20
int str[] = "You collected ";
int stringBuffer[64];
strcpy(stringBuffer, str); //copy 'str' "You collected " into buffer
itoa(strlen(stringBuffer), num); //Transform the number 20 into a string that reads "20" and append it to buffer

Trace(stringBuffer); // stringBuffer now contains "You collected 20", print it to the console.
Hope that helps.

#9 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 25 May 2018 - 08:33 PM

Oh I see, you were making a specific case, as if I knew how many of that item Link would have. (I think)

Nah I don't know how many he will pick up.

 

I could do fine with a counter rather than a string.

 

Perhaps the best option is 4 message pickup strings. Each message string gives you a dummy item, so the message string advances each time. Then the fourth message string gives you a real item, and removes the dummy items so the cycle restarts.

 

EDIT: Also Lut, it's a lie, those rearranged blocks don't really line up.


Edited by Cukeman, 25 May 2018 - 08:41 PM.


#10 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 26 May 2018 - 02:16 AM

Oh.. It sounded like you just wanted to know how to build a string dynamically which is why I suggested to use string.zh; itoa simply means "Integer TO ASCII" or int to string. For some reason we use clib naming for that which is why the procedure names may seem a bit awkward at first.

Maybe if you specify exactly what you are trying to do someone can help you out. You've kind of sort of lost me..; I'm not really sure what else to say.

#11 Cukeman

Cukeman

    "Tra la la, look for Sahasrahla. ... ... ..."

  • Banned
  • Location:Hyrule/USA

Posted 26 May 2018 - 02:54 AM

Basically I want to count the number of times Link uses a warp to go from one screen to another, so that at the end of the game I can have that be one of the totals for the player to look at. And that total will be divided by 4 before the player sees it.


Edited by Cukeman, 26 May 2018 - 02:55 AM.


#12 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 29 May 2018 - 02:01 PM

Basically I want to count the number of times Link uses a warp to go from one screen to another, so that at the end of the game I can have that be one of the totals for the player to look at. And that total will be divided by 4 before the player sees it.


Regular warp, or scripted warp; and is this from one specific location to a second specific location; and no other warps in the quest?

If so, the surest way is to store the screen transitions between those two locations. IDK why you are dividing it by four.

You'd still use itoa() to store the integer into a ZScript string to draw, in your credits, &c.

There's no way to insert into ZQ message strings in 2.50.x. (I have since added that feature, fwiw.)

itoa() Usage:

int n = 126:
int buffer[4];  // Can hold three characters, plus NULL.
itoa(buffer,n); // Converts the literal value of 'n',
                // (126 at present) into a string, using pointer: buffer[]
// This is effectively: buffer[4]="126";
// ...if the value of 'n' changes, you can call itoa() to update the string.

TraceS(buffer); //Traces '126' to the log/console.
That's the basic method for using itoa(). It's easily the default string.zh function that I most-routinely use in my scripts.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users